Background image not fading in

323 views Asked by At

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. 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. 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> 

2

There are 2 answers

2
Shadow Fiend On BEST ANSWER

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

0
ab29007 On

You can use 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>