简体   繁体   English

背景图像不褪色

[英]Background image not fading in

I've been trying to figure out why my background image is not fading in. I've tried using css/jquery and also the w3 route. 我一直在试图弄清楚为什么我的背景图像没有消失。我一直在尝试使用css / jquery以及w3路由。 I can see that the background image is actually showing up and I have checked to see that the jquery code is actually working for any tags I nest inside the body tag. 我可以看到背景图片实际上正在显示,并且已经检查了jquery代码实际上对我嵌套在body标签内的任何标签有效。 I have read other posts but they are not helping. 我读过其他帖子,但没有帮助。

 $(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> 

You can use setTimout 您可以使用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> 

 $(document).ready(function() { $("body").hide().fadeIn(3000); }); 
 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'); } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM