1 2 3 4 5 6 7 8 9 10 11 12 |
$(function(){ // 頁面作用才更新資料 window.onfocus = function(){ setInterval(function(){ search(); }, 10000); }; window.onblur = function(){ for (var i = 1; i < 9; i++) window.clearInterval(i); }; }); |
--
元素出現就作用
- How to tell if a DOM element is visible in the current viewport?
- http://jsfiddle.net/AndyE/d48Cv/1/
- jquery.inview2
1 2 3 4 5 6 7 |
$('div').bind('inview', function(event, isInView) { if (isInView) { $(this).css('background-color', '#f00'); } else { $(this).css('background-color', '#00f'); } }); |
--
元素完整出現才作用
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<div style="width: 300px; height: 300px;"> <p>C</p> </div> <hr/> <script> $(window).scroll(function() { $('div:in-viewport(-320)').css({ 'background-color': '#f00', 'color': '#151612' }).find('p').text('Now in viewport.'); }); </script> |
--
844 total views, 1 views today