Note that there are some explanatory texts on larger screens.

plurals
  1. POSlider with visible slides from sides and costum animation
    primarykey
    data
    text
    <h1>1. slider animation shema n1</h1> <p><img src="https://i.stack.imgur.com/Z9n6x.png" alt="enter image description here"></p> <h1>2. slider animation shema n2</h1> <p><img src="https://i.stack.imgur.com/Cld3D.png" alt="enter image description here"> Imagine that there are two sliders one behind another. Both moves synchroniously, to the same side. The first one moves with inertion, to strech, and the bottom one (the main one) starts moving from start.</p> <h1>3. This is how it should look like in browser</h1> <p><img src="https://i.stack.imgur.com/8TXHP.png" alt="enter image description here"></p> <h1>4. This is what I have achieved so far</h1> <p>HTML</p> <pre><code>&lt;div id="ghostCarousel"&gt; &lt;div id="content"&gt; &lt;div&gt; &lt;img src="http://dqsvds7jo3ykg.cloudfront.net/files/2011/12/Post-Apocalyptic1-820x330.jpg" /&gt; &lt;/div&gt; &lt;div&gt; &lt;img src="http://dqsvds7jo3ykg.cloudfront.net/files/2011/12/Post-Apocalyptic1-820x330.jpg" /&gt; &lt;/div&gt; &lt;div&gt; &lt;img src="http://dqsvds7jo3ykg.cloudfront.net/files/2011/12/Post-Apocalyptic1-820x330.jpg" /&gt; &lt;/div&gt; &lt;div&gt; &lt;img src="http://dqsvds7jo3ykg.cloudfront.net/files/2011/12/Post-Apocalyptic1-820x330.jpg" /&gt; &lt;/div&gt; &lt;div&gt; &lt;img src="http://dqsvds7jo3ykg.cloudfront.net/files/2011/12/Post-Apocalyptic1-820x330.jpg" /&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="bg-block"&gt;&lt;/div&gt; &lt;div id="gcNav"&gt; &lt;a href="#" class="left"&gt;&lt;/a&gt; &lt;a href="#" class="right"&gt;&lt;/a&gt; &lt;/div&gt; </code></pre> <p></p> <p>CSS</p> <pre><code>html, body { padding:0; margin:0; } #ghostCarousel { overflow: hidden; /*position: relative;*/ } #ghostCarousel #content &gt; div { width: 820px; height: 330px; float: left; position: relative; /* nuemus padding reikia padding ploti nustatyt i 0*/ padding-left:15px; padding-right: 15px; /*z-index: 99;*/ } #ghostCarousel #content &gt; div &gt; img { filter: url("data:image/svg+xml;utf8,&amp;lt;svg xmlns=\'http://www.w3.org/2000/svg\'&amp;gt;&amp;lt;filter id=\'grayscale\'&amp;gt;&amp;lt;feColorMatrix type=\'matrix\' values=\'0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\'/&amp;gt;&amp;lt;/filter&amp;gt;&amp;lt;/svg&amp;gt;#grayscale"); /* Firefox 10+, Firefox on Android */ filter: gray; /* IE6-9 */ -webkit-filter: grayscale(100%); /* Chrome 19+, Safari 6+, Safari 6+ iOS */ /*z-index: 99;*/ } #content .active { z-index: 9999; } #content .active img { /*background: #FFF;*/ filter: url("data:image/svg+xml;utf8,&amp;lt;svg xmlns=\'http://www.w3.org/2000/svg\'&amp;gt;&amp;lt;filter id=\'grayscale\'&amp;gt;&amp;lt;feColorMatrix type=\'matrix\' values=\'1 0 0 0 0, 0 1 0 0 0, 0 0 1 0 0, 0 0 0 1 0\'/&amp;gt;&amp;lt;/filter&amp;gt;&amp;lt;/svg&amp;gt;#grayscale") !important; -webkit-filter: grayscale(0%) !important; } .bg-block { width:880px; height: 500px; position: absolute; top: 0px; left: 50%; margin-left: -440px; background: #FFF; /*z-index: 100;*/ } #gcNav { width: 960px; position: absolute; top: 135px; left: 50%; /* move the left edge to the center … */ margin-left: -480px; /* … and move it to the left half the box’ width. */ /*z-index: 9999;*/ } #gcNav a { display: block; width: 40px; height: 80px; background: url("http://bisonai.infoaleja.lt/wp-content/themes/bisonai/img/controls.png") no-repeat; } #gcNav .left { background-position: 0 0; float: left; } #gcNav .right { background-position: -40px 0; float: right; } </code></pre> <p>JS</p> <pre><code> $(function () { var content = '#ghostCarousel #content'; var section = content + ' &gt; div'; var v = $(window).width(); var w = $(section).width(); var c; var itemuKiekis = $('#content div').length; var vidurinioNr; var paddingPlotis = 30; var itemuSarasas = []; function ghostCarousel() { for (var i = 1; i &lt;= itemuKiekis; i++) { itemuSarasas[i] = $('#content div:nth-child(' + (i) + ')').html(); $('#content h3').hide(); $('#content p').hide(); //console.log(itemuSarasas[i]); } if (itemuKiekis % 2 === 0) { c = ((w + paddingPlotis) * $(section).length - v + w) / 2; vidurinioNr = itemuKiekis / 2 + 1; var index = 1; for (var i = vidurinioNr; i &lt;= itemuKiekis; i++) { $('#content div:nth-child(' + i + ')').html(itemuSarasas[index]); $('#content div:nth-child(' + index + ')').html(itemuSarasas[i]); console.log("i:" + i + " index:" + index); index++; } for (var i = 1; i &lt;= vidurinioNr; i++) { $('#content div:nth-child(' + i + ')').html(itemuSarasas[index]); console.log("i:" + i + " index:" + index); index++; } } else { c = ((w + paddingPlotis) * $(section).length - v) / 2; vidurinioNr = (itemuKiekis + 1) / 2; var index = 1; for (var i = vidurinioNr; i &lt;= itemuKiekis; i++) { $('#content div:nth-child(' + i + ')').html(itemuSarasas[index]); //console.log("i:" + i); index++; } for (var i = 1; i &lt; vidurinioNr; i++) { $('#content div:nth-child(' + i + ')').html(itemuSarasas[index]); console.log("i:" + i); index++; } } $('#content div:nth-child(' + vidurinioNr + ')').attr("class", "active"); console.log("v:" + v); console.log("w:" + w); console.log("c:" + c); console.log("itemuKiekis:" + itemuKiekis); console.log("vidurinioNr:" + vidurinioNr); //TODO: keisti ilgi kad tilptu visos ft, jei netelpa $(content).width((w + paddingPlotis * 2) * $(section).length); $(content).css('margin-left', -c); $('#gcNav a.left').click(function (e) { e.preventDefault(); if ($(content).is(':animated')) return false; $('#content .active h3').fadeOut(); $('#content .active p').fadeOut(); $('#content div:nth-child(' + (vidurinioNr + 1) + ')').attr("class", "active"); $('#content div:nth-child(' + (vidurinioNr) + ')').removeClass("active"); $(content).animate({ marginLeft: '-=' + w }, 500, function () { var first = $(section).eq(0); $(section).eq(0).remove(); $(this).animate({ marginLeft: '+=' + w }, 0); $(this).append(first); $('#content .active h3').fadeIn(); $('#content .active p').fadeIn(); }); }); $('#gcNav a.right').click(function (e) { e.preventDefault(); if ($(content).is(':animated')) return false; $('#content .active h3').fadeOut(); $('#content .active p').fadeOut(); $('#content div:nth-child(' + (vidurinioNr - 1) + ')').attr("class", "active"); $('#content div:nth-child(' + (vidurinioNr) + ')').removeClass("active"); $(content).animate({ marginLeft: '+=' + w }, 500, function () { var end = $(section).length - 1; var last = $(section).eq(end); $(section).eq(end).remove(); $(this).animate({ marginLeft: '-=' + w }, 0); $(this).prepend(last); //$('#content div:nth-child(' + vidurinioNr + ')').attr("class","active"); $('#content .active h3').fadeIn(); $('#content .active p').fadeIn(); }); }); } ghostCarousel(); $(window).resize(function () { v = $(window).width(); w = $(section).width(); c = ((w + paddingPlotis) * $(section).length - v) / 2; $(content).css('margin-left', -c); }); }); </code></pre> <p>working jsfiddle example - <a href="http://jsfiddle.net/V9RyW/" rel="nofollow noreferrer">http://jsfiddle.net/V9RyW/</a></p> <p>If you check fiddle, you will see that pictures make straight line and goes one by one when clicked. Also, the incoming photo gets 'active' class.</p> <p>How to modify the code, that 1/3 of 3rd and 5th slide in n1 scheme would be hidden behind 4?</p> <p>Also, how to achieve animation like in shema n2?</p>
    singulars
    1. This table or related slice is empty.
    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