javascript - backgroundSize "cover" not working on Firefox -
this question has answer here:
i using following load ramdom background image each time browser refreshed. on top use 2 z-layers fade in, 1 black trasparent , overlay pattern transparent solid. works fine on chrome , safari firefox refuses fade out layer no1 (black transpartent), , firefox refuses strech images cover background.
<script type="text/javascript"> var totalcount = 6; function changeit() { var num = math.ceil( math.random() * totalcount ); document.body.background = 'images/'+num+'.jpg'; document.body.style.backgroundsize = "cover"; document.body.style.backgroundposition = "center"; } </script> </head> <body style="background-color:#000"> <a style="display:block; position:fixed; left:0; top:0; width:100%; height:100%; cursor:pointer" href="#/"> <div class="overlay fade-out one"> </div> <div class="overlaygrid"> </div> </a> </body> <script type="text/javascript"> changeit(); </script> </html>
and css
.fade-out { opacity:1; -webkit-animation:fadein ease-in 0; -moz-animation:fadein ease-in 0; animation:fadein ease-in 0; -webkit-animation-fill-mode:forwards; -moz-animation-fill-mode:forwards; animation-fill-mode:forwards; } .fade-out.one { -webkit-animation-delay: 0.0s; -moz-animation-delay: 0.0s; animation-delay: 0.0s; } .overlay {display:block;position:fixed;left:0;top:0;width:100%;height:100%; background:#000; z-index:1 } .overlaygrid {display:block;position:fixed;left:0;top:0;width:100%;height:100%; background: url('../assets/bg-overlay-pattern.png'); z-index:2}
you'll need make sure add following css:
html { height: 100%; } body { background-size: cover; background-repeat: no-repeat; height: 100%; }
note: if body doesn't have background already, can set background-size via css without having reset via javascript. keeps js manipulation minimum. same goes styling property (except of course image...unless want have default image).
Comments
Post a Comment