javascript - $ ('#div' ).bind ('scroll' 函数({})) 不起作用

标签 javascript jquery meteor bind

我在这里添加了 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/

相关文章:

javascript - 无法在 Firebase 上使用 foreach 方法获取数据

javascript - 屏幕尺寸变化时的 Angular Bootstrap 范围

benchmarking - Meteor 在众多客户之间共享大量收藏时的效率如何?

javascript - 上传CSV到meteor : _id not defined

javascript - 想要将 .jsp 文件更改为 .java

jquery - 防止 jQuery UI 可调整大小的元素覆盖另一个元素?

javascript - jQuery 源代码中正则表达式的澄清

javascript - 有什么方法可以将单选按钮列表动态更改为选择下拉列表吗?

templates - meteor :检测嵌套模板中的事件

javascript - IE9 将上下文 'this' 转换为对象