作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在页面加载时,我想淡入一个 CSS id,然后在几秒钟后我想淡入另一个 CSS id。有人知道我会为此使用什么 jquery 代码吗?
这是两个id的
#background {
background: url("images/am_photography_bg.jpg") no-repeat center -25px fixed;
background-size: 100%;
height: 100vh;
}
#background-blured {
background: url("images/am_photography_bg_blured.jpg") no-repeat center -25px fixed;
background-size: 100%;
height: 100vh;
opacity: .5;
}
这是我的html
<html>
<head>
</head>
<body>
<section>
<div id="background"></div>
</section>
</html>
有什么想法吗?
我尝试将这段代码添加到我现有的 jQuery 中:
$("#background").delay(1500).animate({
background: url("images/am_photography_bg_blured.jpg") no-repeat center -25px fixed,
opacity: .5,
}, 1000, function() {
// Animation complete.
});
为了使这一切在一起:
$(document).ready(function() {
$('body').css('display', 'none')
$('body').fadeIn(1500);
$("#background").delay(1500).animate({
background: url("images/am_photography_bg_blured.jpg") no-repeat center -25px fixed,
opacity: .5,
}, 1000, function() {
// Animation complete.
});
$("h1").delay(2000).animate({
top: -30,
opacity: 1,
}, 700, function() {
// Animation complete.
});
$('.link').click(function() {
event.preventDefault();
newLocation = this.href;
$('body').fadeOut(500, newpage);
});
});
function newpage() {
window.location = newLocation;
}
但是它坏了。
最佳答案
是这样的吗?
$('#background').addClass('background');
setTimeout(function() {
$('#background').addClass('background-blured');
}, 2000);
.background {
background: blue url("images/am_photography_bg.jpg") no-repeat center -25px fixed;
background-size: 100%;
height: 100vh;
}
.background-blured {
background: red url("images/am_photography_bg_blured.jpg") no-repeat center -25px fixed;
background-size: 100%;
height: 100vh;
opacity: .5;
}
#background {
transition: all 2s ease-in-out;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.1/jquery.min.js"></script>
<section>
<div id="background" class="background"></div>
</section>
关于javascript - 在页面加载时将 CSS id 淡入另一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32624430/
我是一名优秀的程序员,十分优秀!