【发布时间】:2015-01-03 02:08:14
【问题描述】:
我在这里添加了 2 个代码,window.scroll 在我的示例中有效,但第二个将 div 绑定到滚动条上没有。
任何人都知道我做错了什么!?
你知道我在 MeteorJS 工作
这2个代码在同一个js文件中。
$(window).scroll(function() {
lastSession = Session.get('c_info')[Session.get('c_info').current]
if(lastSession.list == 0 && $(window).height() + $(window).scrollTop() >= $(document).height()){
lastItem = $( ".list-item div:last" ).html();
if (lastSession.page == 1){
currentSession().more();
lastItem2 = $( ".list-item div:last" ).html();
} else if( lastItem2 != lastItem) {
currentSession().more();
lastItem2 = $( ".list-item div:last" ).html()
}
}
});
$('#playlist').bind('scroll',function() {
console.log("div is scrolling");
});
我也试过这个:
$('#playlist').scroll(function() {
console.log("div is scrolling");
});
MeteorJS 模板:
<template name="playList">
<div id="playlist" class="playlist show-for-large-up">
{{#each list}}
<a href="/video/{{_id}}" class="large-12 columns" id="pl{{v_id}}">
<div>
<div class="large-7 columns plRight">
<span>{{vTitle}}</span>
</div>
</div>
</a>
{{/each}}
</div>
</template>
也试过了:
$('#playlist').on('scroll',function() {console.log('test')});// not working
尝试更改 id 名称并准备好文档:
$( document ).ready(function (){
$('#pl_list').bind('scroll',function() {
console.log("div is scrolling");
});
})//failed
div 有一个滚动条,列表很长,我有一个这样的 css:
.playlist {
padding: 0;
overflow-y: scroll;
height: 458px;
}
也试过了:
Template.playList.rendered = function () {
console.log("playlist rendered");// i can see this on logs this tells that template is in doom
Meteor.setTimeout(function(){
$('#playlist').on('scroll',function(){
console.log('Scrolling...');
});
}, 2000);// with settimeout i have giveng it 2 more seconds
}
【问题讨论】:
-
你能在演示小提琴中重现吗?
-
哇!那是您正在使用的一些非常古老的 jQuery(> 3 岁...)。从 v1.7 开始,
on()替换了bind()方法。也就是说,这种类型的大多数问题要么归因于选择器,要么归因于元素是动态生成的,并且您需要使用委托事件。 -
@Bartdude 我试过 $('#playlist').on('scroll',function() {});
-
@A.Wolff 我没有重复的 id-s 我现在将发布我的模板
-
@EhsanSajjad 恐怕不行。我使用 MeteorJS 而不仅仅是普通的 html。
标签: javascript jquery meteor bind