【发布时间】:2012-12-22 04:46:40
【问题描述】:
我想使用throttle from underscore.js,但我不知道如何在我的代码中实现它。
<script type="text/javascript">
$(document).ready(function() {
/* Scroll event handler */
$(window).bind('scroll',function(e){
parallaxScroll();
});
});
/* Scroll the background layers */
function parallaxScroll(){
var scrolled = $(window).scrollTop();
$('header').css('top',(0+(scrolled*1))+'px');
$('#balken0').css('top',(-600+(scrolled*1))+'px');
$('#balken1').css('top',(-1465+(scrolled*1))+'px');
$('#balken2').css('top',(-2320+(scrolled*1))+'px');
}
</script>
提前谢谢你!
【问题讨论】:
-
var throttled = _.throttle(parallaxScroll, 100); $(window).scroll(throttled);? -
我对 jquery 很陌生:D
-
嗯,这很好,你知道
throttle做了什么。 -
好的,代码可以工作,但我不希望#balken 完全不动!我的问题是,在 Firefox 中效果很好,但 safari 不行!
-
@JustKidding 查看已接受的答案。stackoverflow.com/questions/8907373/…
标签: jquery underscore.js throttling