How can I create a sticky submenu like mailchimp or campaign monitor?
-
... So when you scroll; the submenu rises to the top and shows always. I just cant figure it out!
-
Answer:
For the fixed positioning, you would use something like this: #sticky{ position: fixed; //fixes the container to a specific place top: 25%; //one quarter of the page from the top } To change that as you scroll, you could do something like this (using jQuery here): $(window).on("scroll", function(){ var $sticky = $("#sticky"); var scrollVar = $(this).scrollTop(); //gives you the scrollY position on the page scrollVar > 250 ? $sticky.css({ "top" : "0%" }) : $sticky.css({"top" : "25%" }) }) This would set the "top" CSS value to 0% if the document has been scrolled at least 250px, or set it to 25% if the document has been scrolled less than that. You'll want to adjust this value if you want it to "hook" to the top of the page at a specific point. The ternary operator (?:) there is basically just a collapsed if/else statement. If you'd like the sticky to "hook" to the top as you pass over it, you could do this instead: $(window).on("scroll", function(){ var $sticky = $("#sticky"); var stickyPosition = $sticky.offset().top; var scrollVar = $(this).scrollTop(); //gives you the scrollY position on the page scrollVar > stickyPosition ? $sticky.css({ "top" : "0%" }) : $sticky.css({"top" : "25%" }) }) Now, as you pass the container, it should automatically attach to the top based on the offset().top value.
Andrew Klatzke at Quora Visit the source
Other answers
check out CSS positioning. and for scrolling you will need some javascript, too.
Bahruz Garamammadov
Related Q & A:
- How can i create a mobile application server?Best solution by Stack Overflow
- How can i create a new blog?Best solution by Yahoo! Answers
- How can I create a new font?Best solution by Yahoo! Answers
- How can I create a cute, artsy, unique facebook profile?Best solution by Quora
- How can I create a yahoo group?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.