gpt4 book ai didi

jquery - 在 jquery 中使用淡入淡出效果更改正文背景图像

转载 作者:技术小花猫 更新时间:2023-10-29 10:19:34 27 4
gpt4 key购买 nike

嘿,我想淡入一个新的背景图片,假设每 60 秒淡出一次。我这样设置背景图片:

body {background-image: url(background.jpg);}

现在我想改变它,所以在 60 秒后它变为 background2.jpg,然后在 60 秒后变为 background3.jpg 等等。

我发现很多东西都没有在体内改变,但只是作为图像......有什么快速解决方案吗?

谢谢!

最佳答案

更新的重新更新:

Even NEWER Fiddle (without arguments.callee)

变化:


重大更新


this previous answer 中获取这段代码的内容并添加了一些金光闪闪的东西(使用我的网站背景存储大声笑)

original fiddle :)

NEW Super Fiddle

Javascript:

$(document).ready(function () {
var img_array = [1, 2, 3, 4, 5],
newIndex = 0,
index = 0,
interval = 5000;
(function changeBg() {

// --------------------------
// For random image rotation:
// --------------------------

// newIndex = Math.floor(Math.random() * 10) % img_array.length;
// index = (newIndex === index) ? newIndex -1 : newIndex;

// ------------------------------
// For sequential image rotation:
// ------------------------------

index = (index + 1) % img_array.length;

$('body').css('backgroundImage', function () {
$('#fullPage').animate({
backgroundColor: 'transparent'
}, 1000, function () {
setTimeout(function () {
$('#fullPage').animate({
backgroundColor: 'rgb(255,255,255)'
}, 1000);
}, 3000);
});
return 'url(http://www.fleeceitout.com/images/field.' + img_array[index] + '.jpg)';
});
setTimeout(changeBg, interval);
})();
});

CSS:

body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
position: relative;
background-image: url(http://www.fleeceitout.com/images/field.2.jpg);
background-size: cover;
background-repeat: no-repeat;
background-position: 0 0;
background-attachment: fixed;
}
#fullPage {
position: absolute;
min-width: 100%;
min-height: 100%;
top: 0;
left: 0;
background-color: rgb(255, 255, 255);
}

关于jquery - 在 jquery 中使用淡入淡出效果更改正文背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20255903/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com