如何在jQuery中切换图像的淡出/淡出效果?
How do I switch the fadeIn/fadeOut effect on an image in jQuery?
我已经把这个工作到'almost ready'状态:http://jsbin.com/icuvit
谁能告诉我如何解决这个问题,所以如果我悬停它变暗,而不是在第一个实例是黑暗的。所以它从正常到>暗
我在下面的js代码中改变什么?
<!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" xml:lang="en" lang="en">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<style>
article, aside, figure, footer, header, hgroup,
menu, nav, section { display: block; }
</style>
</head>
<body>
<div id="mask-div"></div>
<img id="test-img" src="http://www.google.ca/intl/en_ca/images/logo.gif">
<script>
$(document).ready( function() {
$("#mask-div")
.css({
"position": "absolute",
"width": 275,
"height": 110,
"background": "rgba(0, 0, 0, 0.5)",
"display": "block"
})
.mouseover( function() {
$(this).fadeOut("slow");
})
;
$("#test-img").mouseout( function() {
$("#mask-div").fadeIn("slow");
});
});
</script>
</body>
</html>
非常感谢您的指点
你需要交换一些东西:
- 隐藏初始掩码
- 当图像被鼠标悬停时,显示掩码(当掩码还不可见时,您将鼠标悬停在图像上)
- 当掩码被鼠标移出时,隐藏掩码(当掩码已经可见时,您将鼠标移出掩码)
: http://jsbin.com/icuvit/3/edit .
$("#mask-div")
.css({
"position": "absolute",
"width": 275,
"height": 110,
"background": "rgba(0, 0, 0, 0.5)"
})
.mouseout( function() {
$("#mask-div").fadeOut("slow");
})
.hide();
$("#test-img")
.mouseover( function() {
$("#mask-div").fadeIn("slow");
});
和一些首次使用的CSS:
#mask-div {
display: none;
}
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<style>
article, aside, figure, footer, header, hgroup,
menu, nav, section { display: block; }
</style>
</head>
<body>
<div id="mask-div"></div>
<img id="test-img" src="http://www.google.ca/intl/en_ca/images/logo.gif">
<script>
$(document).ready( function() {
$("#mask-div")
.css({
"position": "absolute",
"width": 275,
"height": 110,
"background": "rgba(0, 0, 0, 0.5)",
"display": "none"
})
.mouseout( function() {
$(this).fadeOut("slow");
})
;
$("#test-img").mouseover( function() {
$("#mask-div").fadeIn("slow");
});
});
</script>
</body>
</html>
如果您实际使用一些其他选择器导致多个图像,您仍然可以按照以下方式使用pimvdb的技术。
$('.test-img').each(function(){
var $img = $(this);
$("#mask-div")
.css({
"position": "absolute",
"width": 275,
"height": 110,
"background": "rgba(0, 0, 0, 0.5)"
})
.mouseout( function() {
$("#mask-div").fadeOut("slow");
})
.hide();
$img.mouseover( function() {
$("#mask-div").fadeIn("slow");
});
});
相关文章:
- 如何将淡出图像添加到我的Django页面
- 使用javascript循环淡出图像
- jQuery 淡入淡出图像上的悬停动画会断开链接
- 在单击图像时淡出图像(具有 ID)(因此在单击之前 ID 未知)
- 如何淡出图像,然后使其出现在jquery中的另一个位置
- jQuery在JSON抓取后按顺序淡入淡出图像
- 同时显示淡入和淡出图像数组
- 只有在查看完所有图像后,在图库中循环才开始淡入/淡出图像
- CSS:替换淡出图像
- 使用toggleClass淡入淡出图像
- 使用jQuery交叉淡入淡出图像
- 如何使用jQuery在滚动中淡入淡出图像
- 使用javascript制作淡入淡出图像翻转器
- 在没有实际文本触发的情况下,淡出/淡出图像滚动
- 淡出和淡出图像的问题
- jQuery淡出图像的链接悬停
- 淡入淡出图像之间没有黑色传输-JQuery
- 简单淡出图像上的链接点击
- jQuery循环淡出图像悬停
- Angular在点击指令时淡出图像