Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery - on window scroll run a function without any delay
    primarykey
    data
    text
    <p>I have an issue with a jquery function. You can see a working demo here - <a href="http://dev.sreejesh.in/menuissue/" rel="nofollow">http://dev.sreejesh.in/menuissue/</a> . As you can see when the user scrolls down to the page, I have written a jQuery function(which will triger on scroll) to check scroll pixel. When the browser scrolls to a certain pixel(height of the sidemenu block), the Menu block will stay fixed &amp; rest of the content scrolls as normal. </p> <p>The functionality is working now, however the problem is menublocks makes a jumps when this function runs. I think this is because of the delay in running the function. Hope you guys have any nice trick to fix this.</p> <p>I used an if/else function to check the scroll pixel, so when the scrolled pixel is greater than menublock height it will add a class "fixed" .</p> <p>I use the following code.</p> <p><strong>HTML</strong></p> <pre><code>&lt;div id="globalwrapper"&gt; &lt;div id="menubar"&gt; ---- Menu List items----- &lt;/div&gt; &lt;div id="mainblock"&gt; ----Main content area---- &lt;/div&gt; &lt;/div&gt; </code></pre> <p><strong>jQuery</strong></p> <pre><code>$(document).ready(function(){ $(window).scroll(function() { adjustScroll(); }); }); function adjustScroll(){ var windowHeight = $(window).height(); var menublockHeight = $('#menubar').height(); var scrollValue = $(document).scrollTop(); var posValue = menublockHeight - windowHeight; var menuStatus = $('#menubar').css('left'); $('#menubar').css('minHeight', windowHeight); $('#menubar').css('height', menublockHeight); console.log(menuStatus); $(document).scroll(function() { if(menuStatus == '0px') { if(scrollValue &gt; posValue){ $('#menubar').addClass('fixed'); $('#menubar').css('marginTop', -posValue); }else { $('#menubar').removeClass('fixed'); $('#menubar').css('marginTop', '0px'); } } }); } </code></pre>
    singulars
    1. This table or related slice is empty.
    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