Note that there are some explanatory texts on larger screens.

plurals
  1. POHorizontal scroll content
    primarykey
    data
    text
    <p>i am trying to do a website in wich there is a section where the content has to scroll horizontally as you click on the menu buttons, it also has direction nav, i think i got it with the direction nav but i can not figure it out on how to track the position of my div's in order to move them every time i do click on them. i am trying to use offset(); with jquery but cannot making work. i will appreciate if someone could help me to make my way to achieve this. ill leave you some code and a js fiddle so you guys can see what i have so far.</p> <p>html code:</p> <pre><code>&lt;nav&gt; &lt;ul&gt; &lt;li id="1" class="active-state"&gt;1&lt;/li&gt; &lt;li id="2"&gt;2&lt;/li&gt; &lt;li id="3"&gt;3&lt;/li&gt; &lt;li id="4"&gt;4&lt;/li&gt; &lt;li id="5"&gt;5&lt;/li&gt; &lt;/ul&gt; &lt;/nav&gt; &lt;section id="content"&gt; &lt;div id="wrapper"&gt; &lt;div class="content" id="yellow"&gt;&lt;/div&gt; &lt;div class="content" id="blue"&gt;&lt;/div&gt; &lt;div class="content" id="red"&gt;&lt;/div&gt; &lt;div class="content" id="purple"&gt;&lt;/div&gt; &lt;div class="content" id="green"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/section&gt; &lt;ul id="directionNav"&gt; &lt;li id="left"&gt;left&lt;/li&gt; &lt;li id="right"&gt;right&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>jquery code to do horizontal scroll:</p> <pre><code>$("#3").on("click", horizontalScroll); $("#4").on("click", horizontalScroll2); function horizontalScroll() { console.log($("#3").offset().left); $("#wrapper").animate({ right: ($("#4").offset().left -1200) }); console.log("clicked"); } function horizontalScroll2() { console.log($("#4").offset().left); $("#wrapper").animate({ right: ($("#4").offset().left -1200) }); console.log("clicked"); } </code></pre> <p>here is the fiddle: <a href="http://jsfiddle.net/xtatanx/DY3k3/" rel="nofollow">http://jsfiddle.net/xtatanx/DY3k3/</a></p> <p>thank you very much to all!</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