Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>jQuery for the logic and CSS3 for <code>transition</code> and <code>transform</code>.<br> Multiple galleries + Auto-slide + Pause on hover:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>$(function(){ $('.gallery').each(function() { var $gal = $(this), $movable = $(".movable", $gal), $slides = $("&gt;*", $movable), N = $slides.length, C = 0, itv = null; function play() { itv = setInterval(anim, 3000); } function stop() { clearInterval(itv); } function anim() { C = ($(this).is(".prev") ? --C : ++C) &lt;0 ? N-1 : C%N; $movable.css({transform: "translateX(-"+ (C*100) +"%)"}); } $(".prev, .next", this).on("click", anim); $gal.hover(stop, play); play(); }); });</code></pre> <pre class="snippet-code-css lang-css prettyprint-override"><code>.gallery{ position: relative; overflow: hidden; } .gallery .movable{ display: flex; height: 70vh; transition: transform 0.4s; } .gallery .movable &gt; div { flex:1; min-width:100%; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt; Pause on hover and autoslide &lt;div class="gallery"&gt; &lt;div class="movable"&gt; &lt;div style="background:#0af"&gt;1 &lt;p style="position:absolute; top:400px;"&gt;aaaa&lt;/p&gt;&lt;/div&gt; &lt;div style="background:#af9"&gt;2&lt;/div&gt; &lt;div style="background:#f0a"&gt;3&lt;/div&gt; &lt;/div&gt; &lt;button class="prev"&gt;Prev&lt;/button&gt; &lt;button class="next"&gt;Next&lt;/button&gt; &lt;/div&gt; As many galleries as you want</code></pre> </div> </div> </p> <p>Count the number of slides and put into a <em>counter</em> <code>C</code>.<br> On prev/next click manipulate <code>C</code><br> On autoslide <code>$(this).is(".prev")</code> will also evaluate as <code>false</code> so <code>++C</code> will be used, just like clicking the <em>Next</em> button.<br> On mouseenter simply <code>clearInterval</code> the currently running <code>itv</code> and on mouseleave (the second <code>.hover</code> argument) reinitialize the <code>itv</code></p> <p>The animation is achieved by multiplying C*100 and <code>translateX</code> by <code>- C * 100 %</code> </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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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