背景图像没有褪色

时间:2017-09-11 05:16:06

标签: jquery html css background-image fading

我一直想弄清楚为什么我的背景图片没有消失。我尝试过使用css / jquery以及w3路径。我可以看到背景图像实际显示出来,我已经检查过jquery代码实际上是否适用于我在body标签内嵌套的任何标签。我已阅读其他帖子,但他们没有帮助。

$(document).ready(function(){
    $("body").hide().fadeIn(3000);
});
body {
    background-attachment: fixed;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    background-image: url('../images/index.jpeg');
}
<!DOCTYPE html>
<html>
<head>
<title>TITLE</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="css/styles.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="scripts/myScript.js"></script>
</head>


<body>


</body>
</html> 

 

2 个答案:

答案 0 :(得分:0)

您可以使用setTimout

$(document).ready(function(){
    setTimeout(function() {
    $("body").css("background-image", "url('https://s13.favim.com/orig/170403/aesthetic-forest-nature-photography-Favim.com-5145568.png')");
}, 2000);
});
body {
    background-attachment: fixed;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>just text here</p>

答案 1 :(得分:0)

&#13;
&#13;
$(document).ready(function() {
  $("body").hide().fadeIn(3000);
});
&#13;
html,body{
  margin:0;
  padding:0;
}

div{
  width:100%;
  height: 100vh;
  background-attachment: fixed;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  background-image: url('http://www.nationalgeographic.com/content/dam/science/photos/000/009/940.jpg');
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
</div>
&#13;
&#13;
&#13;