2013-08-28 40 views
-2

我在網頁中使用http://cubiq.org/dropbox/iscroll4/examples/simple/我正在開發並希望在用戶滾動/拖動時優先執行代碼,例如,特定行中的文本應該隨用戶滾動而淡入下。不過,我覺得我可以用這樣的:在滾動元素上執行代碼

$(window).on('scroll', function() { 
       var st = $(this).scrollTop(); 
       $('li.frame1 img').css({ 
        'top' : -(st/3)+"px", 
        'left' : -(st/3)+"px" 
       }); 

      }); 

但用戶實際上向下滾動元素#scroller,而不是窗戶。我怎麼能適應這個或實現我想要做的?

謝謝!

+1

如何定位'#scroller'而不是'window'? – tymeJV

回答

1
$("#scroller").on('scroll', function() { 
    var st = $(this).scrollTop(); 
    $('li.frame1 img').css({ 
     'top' : -(st/3)+"px", 
     'left' : -(st/3)+"px" 
    }); 

}); 

替換document"#scroller"應該做的工作。

0

我相信它應該是你的滾輪的名字。

myScroller = new IScroll('#scorecardWrapper', {}); 
myScroller.on('scroll', function() { 
      var st = $(this).scrollTop(); 
      $('li.frame1 img').css({ 
       'top' : -(st/3)+"px", 
       'left' : -(st/3)+"px" 
      }); 

     });