javascript - jQuery toggle element class based on scroll percentage -


I want to convert var num to percentage instead of pixels in number. how can I do this?

I need it for my site: but they work with pixels, and my website works with% (for example, autoselling on the HD screen or full HD screen)

/ * dynamic top menu position * * /

  var num = 150; // $ 150 ($) (window) .bind ('scroll', function () {if ($ (window) .scrollTop ()> number) {$ ('. Menu') pixels before modifying AddClass ('fixed');} and {$ ('. Menu'). RemoveClass ('fixed');}}); // Use scroll wheel for this Fridley demo  

First, let me know It is a terrific solution to hear every scroll event and call addClass () or removeClass () is expensive every time. // End Promotion

Here is the answer to your question anyway:

  var baseHeight = $ (window). height (); // For the body, use $ ("body"). Height (); Var num = .25; // This is the percentage of vertical scroll $ (window). Bind ('scroll', function) (if ($ (window) .scrollTop () / basehight & gt; number) {$ ('. Menu') AddClass ('fixed');} and {$ ('. Menu '). RemoveClass (' fixed ');}});  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -