Javascript 为什么jquery鼠标事件在Google Chrome中不起作用?
我正在使用这段代码检测div滚动条上的mouseup事件。这段代码在firefox 3/4/5中运行良好,但在google chorme 12/10/5中不起作用 代码:Javascript 为什么jquery鼠标事件在Google Chrome中不起作用?,javascript,jquery,google-chrome,Javascript,Jquery,Google Chrome,我正在使用这段代码检测div滚动条上的mouseup事件。这段代码在firefox 3/4/5中运行良好,但在google chorme 12/10/5中不起作用 代码: jQuery('#slideshow').scroll(function () { jQuery(this).mouseup(function(){ alert("hi it's a mouse up"); }); }); 在firefox中显示警报,但在google chrome中没有显示任何警报 请告诉我
jQuery('#slideshow').scroll(function () {
jQuery(this).mouseup(function(){
alert("hi it's a mouse up");
});
});
在firefox中显示警报,但在google chrome中没有显示任何警报
请告诉我这个问题的解决办法
-提前感谢花生画廊的结果
// Bad
$(window).mouseup(function() { ... });
// Good
window.addEventListener("mouseup", function(event) { ... });
关于花生厨房的结果
// Bad
$(window).mouseup(function() { ... });
// Good
window.addEventListener("mouseup", function(event) { ... });
试试这个:-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Slideshow</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<style type="text/css">
#slideshow
{
width:200px;
padding:10px;
height:200px;
overflow:auto;
}
.slide
{
height:100px;
margin:20px 0px;
background-color:#ccc;
}
</style>
</head>
<body>
<div id="slideshow">
<div class="slide"> </div>
<div class="slide"> </div>
<div class="slide"> </div>
<div class="slide"> </div>
</div>
<script type="text/javascript">
jQuery('#slideshow').scroll(function() {
jQuery(this).mouseup(function() {
alert("hi it's a mouse up");
});
});
</script>
</body>
</html>
试试这个:-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Slideshow</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<style type="text/css">
#slideshow
{
width:200px;
padding:10px;
height:200px;
overflow:auto;
}
.slide
{
height:100px;
margin:20px 0px;
background-color:#ccc;
}
</style>
</head>
<body>
<div id="slideshow">
<div class="slide"> </div>
<div class="slide"> </div>
<div class="slide"> </div>
<div class="slide"> </div>
</div>
<script type="text/javascript">
jQuery('#slideshow').scroll(function() {
jQuery(this).mouseup(function() {
alert("hi it's a mouse up");
});
});
</script>
</body>
</html>
在这里:
这与脚本底部的鼠标盖有冲突。
原因鼠标盖
实际上已经“停止”了多媒体资料
刚刚从.scroll()函数中删除了mouseup
,并将其添加到where下方
我们已经有了一个mouseout侦听器:
$('#slideshow').bind('mouseover mouseout', function(e) {
if (e.type === 'mouseover') {
clearTimeout(interv);
$('#test').html('Stop on mouseover');
} else {
$('#slideshow').animate({scrollLeft: iw * (counter - 1)}, 1000);
start();
}
});
在这里:
这与脚本底部的鼠标盖有冲突。
原因鼠标盖
实际上已经“停止”了多媒体资料
刚刚从.scroll()函数中删除了mouseup
,并将其添加到where下方
我们已经有了一个mouseout侦听器:
$('#slideshow').bind('mouseover mouseout', function(e) {
if (e.type === 'mouseover') {
clearTimeout(interv);
$('#test').html('Stop on mouseover');
} else {
$('#slideshow').animate({scrollLeft: iw * (counter - 1)}, 1000);
start();
}
});
如果我在同一个脚本中使用mousedown,那么它在两个浏览器中都可以正常工作如果我在同一个脚本中使用mousedown,那么在两个浏览器中都可以正常工作。我对它进行了研究,得出结论,鼠标向上移动和滚动在chrome中处于竞争状态,所以在我的情况下最好使用mouseover。竞争状态是我知道的唯一原因,但是我还是不太清楚为什么要用鼠标,我也不太清楚。这就是为什么我把它拿走了更新为新版本(修复了一些小错误)是的,我对它进行了研究,得出结论,在chrome中,鼠标向上和滚动处于竞争状态,所以最好在我的情况下使用鼠标悬停。竞争状态是我知道的唯一原因,但我仍然不太清楚鼠标悬停的原因。这就是为什么我把它拿走了使用更新版本更新(修复了小错误)