Jquery .mouseover()不工作(抓我)
Jquery .mouseover() not working (catch me)
我正在做功课,我试图添加更多的鼠标悬停,但它不工作
$("button").mouseover(function() {
$(this).css({
left: (Math.random() * 300) + "px",
top: (Math.random() * 300) + "px",
}, 1);
});
button {
position: absolute;
top: 400px;
left: 500px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<h1>Catch me if you can !</h1>
<div class="main"></div>
<button>
<img src="cat/grey-cat-001.gif">
</button>
</body>
这是因为每个元素的默认position
都是static
,这不会对top
, left
, right
或bottom
样式产生任何影响。
所以你只需要为按钮添加HTML元素默认定位为静态。
静态定位元素不受top, bottom, left和right属性的影响。
position: relative
或position: absolute
,就像下面的代码片段:
$("button").mouseover(function() {
$(this).css({
left: (Math.random() * 300) + "px",
top: (Math.random() * 300) + "px",
}, 1);
});
button {
position: relative;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<body>
<div class="main"></div>
<button>
<img src="cat/grey-cat-001.gif">
</button>
</body>
相关文章:
- 无法让pdfmake为我工作
- 我做了一个jquery幻灯片,但没有;我工作不好,我该怎么办
- Jon Raasch jQuery Slideshow Script 在 Chrome 中无法为我工作
- .replace() 不再为我工作
- ModalDialog窗体没有'我工作不好
- Javascript显示隐藏下拉列表;我工作不好
- 为什么不是'改变我工作价值观的逻辑
- Javascript Ajax加载程序gif没有'我工作不好
- 使用Javascript进行URL验证;我工作不好
- iPhone:span点击不'我工作不好
- IE8和getElementById没有'我工作不好
- jquery .replace(/.)不是为我工作,而是为别人工作
- jQuery动画API不为我工作
- 有什么办法让我工作与这100,000项新行分隔字串
- Jquery .mouseover()不工作(抓我)
- 如何修改给定的代码打开两个链接在一次点击(没有解决方案为我工作)
- 事件.目标在angular js中不为我工作
- 高图数据从ajax它不为我工作
- 隐藏菜单向下滚动,然后显示菜单时,向上滚动达到0 [javascript]不为我工作
- isroll停止滚动左/右(水平),不为我工作,我做错了