標籤:android style blog color 使用 os io for
大家好,又到了隨機文章的時間,請使用手機開啟示範網站,然後像搖妹子一樣搖晃手機,你會發現非常牛逼的事情,炫酷吧。該功能已經整合在Oconnor1.8中。本文主要講解這貨的原理。首先需要下載shake.js,shake.js github地址,我們只需要裡面的shake.js,然後引入。添加“搖一搖”事件監聽window.addEventListener(‘shake‘, shakeEventDidOccur, false);//function to call when shake occursfunction shakeEventDidOccur () { //put your own code here etc. if (confirm("Undo?")) { }}取消監聽window.removeEventListener(‘shake‘, shakeEventDidOccur, false);隨機文章實現方式JS代碼,當然在這之前需要進入shake.js指令碼window.addEventListener(‘shake‘, shakeEventDidOccur, false);//function to call when shake occursfunction shakeEventDidOccur () { jQuery.post(Bigfa.ajaxurl, { action : ‘random_post‘, }, function(data) { window.location.href = data; });}下面的代碼扔到functions.php中,如果你已經添加了上一篇隨機文章的代碼這裡就不需要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‘ );function bigfa_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 搖 it。瀏覽器和裝置支援情況iOS Safari 4.2.1 (and above)Android 4.0.3 (default browser)Opera Mobile (Android)BlackBerry PlayBook 2.0Firefox for AndroidFirefoxOS Devices