Windows 上 Chrome/Safari 中的 Jquery mousedown mouseup

发布于 2025-01-06 08:10:02 字数 685 浏览 5 评论 0原文

我创建了一个可以用鼠标滚动的页面,就像谷歌地图一样,但是当用户单击一个对象时,我希望它显示隐藏的东西,我想出了一个非常简单的解决方案:

var clicking = false;

//mouse clicked down
$(".tile").mousedown(function () {
    clicking = true;
});

//if mousemoves whilst its clicked down dont do mouse up as we are scrolling page
$(".tile").mousemove(function () {
    if (clicking == true) {
        clicking = false;
    }
});

//So if mouse hasnt moved show the hidden object
$(".tile").mouseup(function () { 
    if (clicking == true) {
        //Show the hidden thing
    }
}

这适用于所有Windows 上除了 chrome 和 safari 之外还有哪些浏览器?那么也许与 webkit 有关?如果我在这些浏览器中双击,它就可以工作,但如果我单击一次,它会更喜欢。我想知道是否有人遇到过这个问题或知道解决方案?希望这是有道理的。

谢谢

I have created a page that can scroll with the mouse, like google maps, but when the user does a single click on an object, i want it to show something hidden, i have come up with a very simple solution:

var clicking = false;

//mouse clicked down
$(".tile").mousedown(function () {
    clicking = true;
});

//if mousemoves whilst its clicked down dont do mouse up as we are scrolling page
$(".tile").mousemove(function () {
    if (clicking == true) {
        clicking = false;
    }
});

//So if mouse hasnt moved show the hidden object
$(".tile").mouseup(function () { 
    if (clicking == true) {
        //Show the hidden thing
    }
}

This works in all browsers apart from chrome and safari on windows? so maybe something to to with webkit? It works if i double click in these browsers but would prefer if its a single click. I was wondering if anyone has come across this problem or knows of a solution? Hope this makes sense.

Thanks

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

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

发布评论

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

评论(1

自此以后,行同陌路 2025-01-13 08:10:02

mousedown 或 mouseup 在所有浏览器中都能完美工作,包括 Windows 上的 chrome 和 safari

,如果不适合您,请使用最后的 jQuery,也可以尝试:

$(".tile").bind("mousedown",function () { 
    if (clicking == true) {
        //Show the hidden thing
    }
}

mousedown OR mouseup work perfectly in all browsers include chrome and safari on windows

if not work for you, use last jQuery,also try :

$(".tile").bind("mousedown",function () { 
    if (clicking == true) {
        //Show the hidden thing
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文