到目前为止,我已经尝试了很多事情来达到以下效果,但没有成功:
<script type="text/javascript">
var x = 0;
while (true) {
/* change background-image of #slide using some variation
of animate or fadeIn/fadeOut with or without setTimeout */
x++;
}
</script>
有什么想法吗?
最佳答案
您可以淡化背景颜色,但不能淡化背景图像。解决此问题的方法是将图像设置为 <img>
标签并默认隐藏它们 display:none;
.给你的图片position:absolute
和 z-index:-1
所以他们就像背景一样,在其他一切事物的背后。
这是一个图像逐个淡出的简单示例。
HTML
<img src=".." />
<img src=".." />
CSS
img{
position:absolute;
z-index:-1;
display:none;
}
jQuery
function test() {
$("img").each(function(index) {
$(this).hide();
$(this).delay(3000* index).fadeIn(3000).fadeOut();
});
}
test();
在 http://jsfiddle.net/RyGKV/ 查看工作示例
关于javascript - 使用 jQuery 淡入淡出背景图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5533171/