0

I have two background elements (one picture one a video). How do I display the picture only when the page first gets loaded and then use the video background only when the page gets refreshed?

I tried a no-repeat in the image, but no success. I don't think local storage counter would work, because each time the page gets loaded from scratch it would remember the previous number.

<!-- image background -->
<style>
html { 
background: url("{% static 'images/calc_background2.jpg' %}") no- 
repeat center center fixed; 
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
.fullscreen-bg {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        overflow: hidden;
        z-index: -100; 
        }

.fullscreen-bg__video {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        }
</style>

<!-- video background -->
<div class="fullscreen-bg">
<video autoplay muted poster="{% static 'images/background2.jpg' %}" 
class="fullscreen-bg__video" id="myVideo"> <!--autoplay-->
<source src="{% static 'videos/calc_background_vid109.mp4' %}" 
type="video/mp4">
</video>
</div>   

When the page first opens, we see the image background. when the page is refreshed the video background would play. Thanks for the help!

  • Using `localstorage` should work fine. Just record when the page is visited and check to see if it has been visited before. You wouldn’t be able to do this in pure CSS though – yaakov Jul 02 '19 at 23:51
  • Try using the sessionStorage object https://stackoverflow.com/questions/5523140/html5-local-storage-vs-session-storage/5523174#5523174 – Caleb Loera Jul 03 '19 at 00:25
  • Thanks! sessionStorage works! – tobias wettstein Jul 04 '19 at 21:58

0 Answers0