Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I rotate(or change) background image using CSS and Javascript
    primarykey
    data
    text
    <p>I have taken a look through stackoverflow for hours now, and I have found a topic similar to what I am trying to achieve</p> <p><a href="https://stackoverflow.com/questions/13846896/how-to-change-the-background-image-css-attribute-with-javascript">JavaScript, How to change the background of a div tag every x seconds</a></p> <p>When I modify this solution in my script, I get no background image at all so I thought I would come back to the source to get some fresh eyes and thoughts.</p> <p>Here is my setup: HTML</p> <pre><code> &lt;div id="Background"&gt;&lt;/div&gt; </code></pre> <p>CSS:</p> <pre><code> .background-1 { background: url('Images/mybg1.jpg'); -webkit-transition: background 500ms linear; -moz-transition: background 500ms linear; -o-transition: background 500ms linear; -ms-transition: background 500ms linear; transition: background 500ms linear; } .background-2 { background: url('Images/mybg2.jpg'); -webkit-transition: background 500ms linear; -moz-transition: background 500ms linear; -o-transition: background 500ms linear; -ms-transition: background 500ms linear; transition: background 500ms linear; } </code></pre> <p>Javascript in the head tag</p> <pre><code> &lt;script&gt; $(document).ready(function(){ setInterval(function() { if($('#background').hasClass('background-1')) { $('#background').addClass('background-2'); setTimeout(function() { $('#backdrop').removeClass('background-1'); }, 1000); } else if($('#background').hasClass('background-2')) { $('#background').addClass('background-1'); setTimeout(function() { $('#backdrop').removeClass('background-2'); }, 1000); } }, 2000); }); </code></pre> <p> I want to somehow be able to use several images for the background and have them change out every 5 or so seconds. How do I do this?</p> <p>Here is what I have tried HTML</p> <pre><code> &lt;div id="Background"&gt; &lt;img src="&lt;%=skinpath%&gt;/images/mybg2.jpg" class="bgM"/&gt; &lt;img src="&lt;%=skinpath%&gt;/images/mybg1.jpg" class="bgM"/&gt; &lt;/div&gt; </code></pre> <p>CSS:</p> <pre><code> #Background, img.bgM { background:#fff no-repeat 0 bottom;position:absolute;bottom:0;min-width:960px;min-height:100%;z-index:-99999; background-position: top center; } </code></pre> <p>Javascript:</p> <pre><code> &lt;dnn:DnnJsInclude runat="server" FilePath="js/jquery.cycle.all.js" PathNameAlias="SkinPath" /&gt; &lt;script type="text/javascript" src="http://code.jquery.com/jquery-1.6.3.min.js"&gt;&lt;/script&gt; $(document).ready(function() { $('#Background').cycle({ fx: 'fade', pager: '#smallnav', pause: 1, speed: 1800, timeout: 3500 }); }); </code></pre> <p>This last solution worked however I could not get the image to position top center(even when specified in the css.) Any help on this is greatly appreciated!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload