在 IE8 和黑莓 playbook javascript setInterval 函数中无法正常工作

发布于 2025-01-07 15:19:56 字数 1320 浏览 3 评论 0原文

我定义了一个点击,除了两个之外,它可以按需要工作。我按如下方式绑定点击事件:

$('#next_item').bind(myDown,function (e) {
    config.scrolling = true;
    config.scrollTimer = setInterval(function (e) {
        if(!config.scrolling) return false;
        if(myScroll.x >= myScroll.maxScrollX){              
            myScroll.scrollTo((config.itemWidth+config.itemBoxSpacing), 0, 400, true);
        }else{
            config.scrolling=false;
            clearInterval(config.scrollTimer);
        }
    }, 100);
    return false;
});

我正在使用 iScroll 4#next_item 用于在单击时滚动动态添加的 div。使用 setInterval function() 是因为单击时我想一次滚动一个 div,而在 mousedown 时我希望 div 滚动直到我执行 mouseup。现在的问题是在 Blackberry Playbook 中单击一次多个 div 滚动,但在 iPad、Android 平板电脑和桌面浏览器(包括 IE8)中工作正常。另外,当我在 blacberry playbook 中执行 mousedown 时,div 会继续滚动直到结束,并且在 mouseup 时不会立即停止,对于 IE8,div 会停止并且滚动似乎 setInterval 无法正常工作。需要进行哪些更改才能在 IE8 和黑莓 playbook 中实现此功能

更新:

var isIOS = config.isIpad || config.isIphone || config.isAndroid;
var myDown = isIOS ? "touchstart" : "mousedown";
var myUp = isIOS ? "touchend" : "mouseup";

$('#next_item').bind(myUp,function (e) {
    config.scrolling = false;
    clearInterval(config.scrollTimer);
    return false;
});

I have a defined a click which works as desired in all except two. I am binding the click event as follows :

$('#next_item').bind(myDown,function (e) {
    config.scrolling = true;
    config.scrollTimer = setInterval(function (e) {
        if(!config.scrolling) return false;
        if(myScroll.x >= myScroll.maxScrollX){              
            myScroll.scrollTo((config.itemWidth+config.itemBoxSpacing), 0, 400, true);
        }else{
            config.scrolling=false;
            clearInterval(config.scrollTimer);
        }
    }, 100);
    return false;
});

I am using iScroll 4. The #next_item is used to scroll the dynamically added div onclick. setInterval function() is used because on single click i want to scroll one div at a time and on mousedown i want the div to scroll till i do mouseup. Now the problem is on single click more then one div scroll at a time in blackberry playbook but works fine in ipad, android tablet and desktop browser including IE8. Also when i do mousedown in blacberry playbook the div keeps on scrolling till end and does not stop immediately on mouseup and for IE8 the div stops and scroll seems like setInterval is not working properly. What changes needs to be done to make this work in both IE8 and blackberry playbook

Update :

var isIOS = config.isIpad || config.isIphone || config.isAndroid;
var myDown = isIOS ? "touchstart" : "mousedown";
var myUp = isIOS ? "touchend" : "mouseup";

$('#next_item').bind(myUp,function (e) {
    config.scrolling = false;
    clearInterval(config.scrollTimer);
    return false;
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我已经解决了黑莓的问题。我只需更改一行代码即可。

var isIOS = 'ontouchstart' in document.documentElement; /*This detects all touch devices*/

在我之前的代码中,我没有检测到黑莓剧本,因此它接收了 mousedown 事件,这导致触摸设备的默认 touchstart 事件与 mousedown 事件一起触发,因此意想不到的结果。

我还是没能解决IE8的问题。请任何人建议如何处理 IE8。

I have solved the blackberry problem. I had to just change one line of my code.

var isIOS = 'ontouchstart' in document.documentElement; /*This detects all touch devices*/

In my earlier code i was not detecting blackberry playbook and so it was receiving the mousedown event which caused the default touchstart event for touch devices to trigger along with the mousedown event and hence unexpected result.

I still could not solve the IE8 issue. Please anyone suggest what to do for IE8.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文