我在这里添加了 2 个代码,window.scroll 适用于我的示例,但第二个代码不适用于将 div 绑定(bind)到滚动条。
谁知道我做错了什么!?
只是让你知道我正在 MeteorJS 中工作 <- 我不认为这是问题 bc。窗口滚动有效。
这两个代码位于同一个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
}
最佳答案
试试这个 -
$(document).ready(function(){
$('#playlist').on('scroll',function(){
console.log('Scrolling...');
});
});
关于javascript - $ ('#div' ).bind ('scroll' 函数({})) 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26781664/