【问题标题】:JQuery mobile - can I detect scrollstart on the page content rather than the document?JQuery mobile - 我可以在页面内容而不是文档上检测滚动启动吗?
【发布时间】:2014-06-19 22:48:13
【问题描述】:

我正在尝试使用 JQuery mobile 检测滚动启动,如果我使用以下它可以工作:

   $(document).bind("scrollstart", function() {

        console.log("scroll start detected");

    });

但是,每次滚动整个页面时都会记录。我只想检测页面内容上的滚动,而不是整个页面(文档)滚动时。

我尝试过如下各种尝试:

   $("#myContent").bind("scrollstart", function() {

        console.log("scroll start detected");

    });

   $("#myPage").bind("scrollstart", function() {

        console.log("scroll start detected");

    });

但除了使用文档外,我尝试的任何方法似乎都不起作用。是否可以在文档以外的任何内容上检测到滚动启动?

【问题讨论】:

    标签: jquery jquery-mobile scroll document domdocument


    【解决方案1】:

    您必须将您的选择放在引号中:

    $('#myContent').bind("scrollstart", function() {
    
            console.log("scroll start detected");
    
        });
    
       $('#myPage').bind("scrollstart", function() {
    
            console.log("scroll start detected");
    
        });
    

    【讨论】:

    • 对不起,这只是我的伪代码,在我的应用程序中它们被引用了
    【解决方案2】:

    根据他们的文档,您可以使用 Steady.jsscrollElement 选项来执行此操作。

    【讨论】:

    • 你知道 JQuery 是否不可能吗?如果可能,我想避免添加后续库,但如果无法使用 JQuery,我将不得不研究它们。
    • 我自己没有使用过这个库,但如果你担心大小,它只有 5.34 KB。我想您可以查看它们的源代码(只有 200 行)并选择您需要的部分并在 jQuery 中重新创建它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多