Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd class to li item of element currently in view
    primarykey
    data
    text
    <p>I have smooth scrolling to element. Active class is added to selected li. Everything is working fine until i scroll down with mouse, than active class is not adding to current element li.</p> <p>I am using: </p> <pre><code>&lt;ul class="features"&gt; &lt;li class="active"&gt;&lt;a href="#block1"&gt;block 1&lt;/a&gt;&lt;/li&gt; &lt;li class="active"&gt;&lt;a href="#block2"&gt;block 2&lt;/a&gt;&lt;/li&gt; &lt;li class="active"&gt;&lt;a href="#block3"&gt;block 3&lt;/a&gt;&lt;/li&gt; &lt;li class="active"&gt;&lt;a href="#block4"&gt;block 4&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;div id="block1"&gt;my content....&lt;/div&gt; &lt;div id="block2"&gt;my content....&lt;/div&gt; &lt;div id="block3"&gt;my content....&lt;/div&gt; &lt;div id="block4"&gt;my content....&lt;/div&gt; </code></pre> <p>Jquery: </p> <pre><code>$('.menu-features li &gt; a').click(function() { $('.menu-features li').removeClass(); $(this).parent().addClass('active'); }); $('a[href^="#"]').click(function() { $('html,body').animate({ scrollTop: $(this.hash).offset().top-120}, 700); return false; e.preventDefault(); }); </code></pre> <p>I tried to use <a href="http://imakewebthings.com/jquery-waypoints/" rel="nofollow">waypoints</a> plugin to detect element in view, but how to mark li with the same id as blocks id?</p> <p>i used:</p> <pre><code>$('#block3').waypoint(function(direction) { $('.menu-features li').addClass('test') }); </code></pre> <p>but it adds test class to all li elements, but not for current in view.</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.
    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