Use Shake.js to let your blog support shake a Shake

Source: Internet
Author: User
Tags event listener

hello everyone, again to the time of the random article, please use the mobile phone to open the demo site, and then shake the phone like a sister, you will find very good things, cool bar. This feature is already integrated in the Oconnor1.8. This article mainly explains the principle of the goods. First we need to download the Shake.js,shake.js GitHub address, we only need the inside of the shake.js, and then introduced. Add "Shake" event listener Window.addeventlistener (' Shake ', shakeeventdidoccur,false);//function to call when shake occursfunctionshakeeventdidoccur () {//put your own code here etc.    if(Confirm ("Undo?") {}} to cancel the listener Window.removeeventlistener (' Shake ', shakeeventdidoccur,falserandom article implementation way JS code, of course, before this need to enter the Shake.js script Window.addeventlistener (' Shake ', shakeeventdidoccur,false);//function to call when shake occursfunctionshakeeventdidoccur () {jquery.post (Bigfa.ajaxurl, {action:' Random_post ',                }, function(data) {Window.location.href=data; });} The following code is thrown into functions.php, and if you have added the code for the previous random article, there is no need for Wp_enqueue_script (' Key ',true); Wp_localize_script (' Key ', ' BIGFA ', Array ("Ajaxurl" = Admin_url (' admin-ajax.php '))) ; Add_action (' Wp_ajax_random_post ', ' bigfa_random_post '); Add_action (' Wp_ajax_nopriv_random_post ', ' bigfa_random_post ' );functionBigfa_random_post () {$posts= Get_posts (' Post_type=post&orderby=rand&numberposts=1 '); foreach ($posts as $post) {$link=Get_permalink ($post);    } Echo $link; Exit;} Ok. Just shake it. Browser and device support scenarios for iOS Safari4.2.1(and above) Android4.0.3 (defaultbrowser) Opera Mobile (Android) BlackBerry PlayBook2.0Firefox forAndroidfirefoxos Devices

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.