Selectors
如果頁面寬度小於1024就隱藏同時屬於.navigation.post-navigation這兩個類的元素:
if(jQuery(window).width()<1024){jQuery("#aa").show();jQuery('.navigation.post-navigation').hide();}else{jQuery("#leftShare").show();}
});[/code]
<p>根據時間觸發事件:</p>
[code language="javascript"]
//默認30秒
var timeWaitSec=30000;
//檢查用戶在文章中是否設置了新的執行時間
if((typeof timeWaitSecNew!='undefined') && (timeWaitSecNew>1)){
timeWaitSec = timeWaitSecNew;
}
setTimeout("do_sth()", timeWaitSec);
根據頁面滾動百分比觸發一次性事件,:
var done = false;
jQuery(window).scroll(function(){
var wintop = jQuery(window).scrollTop(), docheight = jQuery(document).height(), winheight = jQuery(window).height();
var scrolltrigger = 0.65;
if(jQuery(window).width()<1024){scrolltrigger = 0.45;}else{scrolltrigger = 0.65;}
//console.log('%scrolled='+(wintop/(docheight-winheight))*100);
if (((wintop/(docheight-winheight)) > scrolltrigger)&&(!done)) {
do_sth();
done = true;
}
});
有時找到到js中中文string如\u8d70\u4e00\u6b65這樣的,是被轉換成了Unicode,可以用站長工具的Unicode轉換工具轉換回來。
如果找到的js文件是minified的,而又需要修改其中內容的化,可以用在線unminify工具進行還原。
倒計時
var wait=5;
timeOut();
function timeOut(){
if(wait==0){
feedbackObj.fadeOut(100,function(){
feedbackObj.remove();
});
$('#opacity-mask').fadeOut(100);
}else{
setTimeout(function(){
wait--;
$('.close-seconds>b').text(wait);
timeOut();
},1000)
}
}
使用谷歌的jQueryCDN,如果CDN失敗則用自己服務器上的
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript">
window.jQuery || document.write('<script type="text/javascript" src="/common/js/jquery.min.js"><\/script>')
</script>
本文更新於 2016/06/29。