[英]Javascript running more than once when its not intended to
我在一次運行時遇到麻煩,我不確定我做錯了什么,因為在我添加滾動高度效果之前效果還不錯。
$(window).scroll(function() {
var y_scroll_pos = window.pageYOffset;
var scroll_pos_test = 450;
if(y_scroll_pos > scroll_pos_test) {
$('#coins').lazylinepainter(
{
"svgData": pathObj,
"strokeWidth": 4,
"strokeColor": "#8E9CCD"
}).lazylinepainter('paint');
}
John Resig的博客文章描述了如何正確處理多次觸發的滾動事件: http : //ejohn.org/blog/learning-from-twitter/
長話短說,您需要定期檢查用戶是否滾動並執行代碼(如果已執行)。 您的代碼應如下所示(摘自同一篇博客文章):
var outerPane = $details.find(".details-pane-outer"),
didScroll = false;
$(window).scroll(function() {
didScroll = true;
});
setInterval(function() {
if ( didScroll ) {
didScroll = false;
// Check your page position and then
// Load in more results
}
}, 250);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.