【发布时间】:2018-08-03 18:24:08
【问题描述】:
我在 HTML 中有一个带有源图像的 img 标记;然后我会在鼠标悬停时将图像切换到另一个图像;正是我在 rel 属性中设置的图像。
然后在鼠标移出时,切换回源图像。
我写了这个脚本,但它不起作用;这个问题肯定是由于错误使用了“元素”,但我无法解决。
function hover(element) {
$(element).fadeOut(1000, function(element) {
element.setAttribute("src", element.attr("rel"));
}).fadeIn(1000);
return false;
}
function unhover(element) {}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<img id="image"
src="http://www.google.com/logos/2011/trevithick11-hp.jpg"
rel="http://www.google.com/logos/2011/mothersday11-hp.jpg"
onmouseover="hover(this);"
onmouseout="unhover(this);"
/>
解决后我将专注于 mouseout 事件
【问题讨论】:
标签: javascript jquery