gpt4 book ai didi

javascript - jQuery Mobile 滚动事件

转载 作者:太空宇宙 更新时间:2023-11-04 02:42:57 26 4
gpt4 key购买 nike

在让滚动系列事件发挥作用方面存在问题(根本不是设计的那样)。一直在浏览所有与此相关的文章、代码建议和其他帮助主题,但没有人能解释为什么这个示例根本不起作用:

基本页面html:

<!DOCTYPE html> 
<html>
<head>
<title>JQM Test</title>

<script src="/inc/jQuery/jquery-1.11.3.js"></script>
<script src="/inc/jQuery/mobile/jquery.mobile-1.4.5.min.js"></script>
<script type="text/javascript">
var scroll = 0;
$(function() {
$(window).on('scroll',function(e) {
console.log("Scrolled - "+scroll);
scroll++;
});
});
</script>
</head>
<body>
Contents blah blah.
</body>
</html>

好的,如果你复制粘贴,包含文件需要替换,并且版本可能不同。 Anwyays 的行为。当我取出 jquery.mobile 包含时,脚本按预期工作,只要滚动位置发生变化,就会将滚动注释记录到控制台中。

当我包含 jquery.mobile 时,它​​会在页面加载时触发一次,仅此而已。已尝试在 jquery 脚本部分、scrollstart 和 scrollstop 事件中更改文档/窗口。甚至尝试使用 native javascript 将 even 显式绑定(bind)到滚动条。同样的结果,在没有包含 jqm 的情况下一切正常,但在我包含 jqm 时失败。

有人可以向我解释为什么 JQM 会破坏滚动功能吗?

编辑:

已尝试使用以下 JS 函数获得完全相同的结果(在添加 JQM 包含之前起作用)

    $(document).on("scrollstart",function(){
****

$(document).on("scrollstop",function(){
****

$(window).on("scrollstart",function(){
****

$(window).on("scrollstop",function(){
****


$(document).scrollstart(function(){
****

$(document).scrollstop(function(){
****

$(window).scrollstart(function(){
****

$(window).scrollstop(function(){
****

window.onscroll=myFunction;

document.onscroll=myFunction;

window.attachEvent("scroll",myFunction,false);

document.attachEvent("scroll",myFunction,false);

最佳答案

试试这个:

   $(function() {
$(window).on('scroll',function(e) {
console.log("Scrolled - "+scroll);
window.scrollBy(100, 0); // for scroll horizontally.
});
});

关于javascript - jQuery Mobile 滚动事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34348511/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com