Note that there are some explanatory texts on larger screens.

plurals
  1. POCoding slider navigation
    primarykey
    data
    text
    <p>** Edit ** Here is my jsfiddle: <a href="http://jsfiddle.net/t5vSA/4/" rel="nofollow">http://jsfiddle.net/t5vSA/4/</a></p> <p>I want to create my own slider with navigation. Yes, I've read tutorials as there are thousands of them, but I can't seem to grasp the concept of this bullet navigation, so I'm asking for help to understand it. I do not want a suggestion for a plugin.</p> <p>My slider is set up so that it has a large width with overflow:hidden, and then clicking the bullet will give a positive/negative <code>margin-left</code> to the slide before or after the clicked upon slide. </p> <p>This is my code so far. </p> <pre><code>&lt;div id="slides" width="500px;"&gt; &lt;div class="slide" id="0" style="width:500px;"&gt; &lt;p&gt;Content&lt;/p&gt; &lt;/div&gt; &lt;div class="slide" id="1" style="width:500px;"&gt; &lt;p&gt;Content&lt;/p&gt; &lt;/div&gt; &lt;div class="slide" id="2" style="width:500px;"&gt; &lt;p&gt;Content&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;ul id="menu"&gt; &lt;li&gt;0&lt;/li&gt; &lt;li&gt;1&lt;/li&gt; &lt;li&gt;2&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>CSS</p> <pre><code>#wrapper { overflow:hidden } #slides { overflow:hidden; width:500px; height:500px; } .slide { display:inline-block; height:500px; float:left; } </code></pre> <p>JS</p> <pre><code>$(document).ready(function(){ var numSlides = $('#slides .slide').length; var slideWidth = $('#slides .slide').width(); var totalWidth = slideWidth * numSlides; // Assign total width of slides $('#slides').css('width', totalWidth); // Assign width of each slide $('#slides .slide').css('width', slideWidth); // Loop through slides? $('#slides .slide').each(function(i) { }); // On clicking the navigation $('ul#menu li').click(function(e) { // Does the sliding I want but doesn't really work. $('#slides .slide').prev().animate({'margin-left': '-' + slideWidth}); e.PreventDefault(); }); }); </code></pre> <p>I'm stumped on the click...how would I go about doing this? I'd like to at least understand what I'm doing instead of using another bloated slider plugin.</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.
    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