Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // menu scrolling and activation for id
- var lastId,
- topMenu = jQuery("#top-navigation"), // here #top-navigation is id of <ul id="top-navigation"></ul>
- topMenuHeight = topMenu.outerHeight()+15,
- menuItems = topMenu.find('a[href^="#"]'),
- scrollItems = menuItems.map(function(){
- var item = jQuery($(this).attr("href"));
- if (item.length) { return item; }
- });
- menuItems.click(function(e){
- var href = jQuery(this).attr("href"),
- offsetTop = href === "#" ? 0 : $(href).offset().top-topMenuHeight+1;
- jQuery('html, body').stop().animate({
- scrollTop: offsetTop
- }, 300);
- e.preventDefault();
- });
- jQuery(window).scroll(function(){
- var fromTop = $(this).scrollTop()+topMenuHeight;
- var cur = scrollItems.map(function(){
- if ($(this).offset().top < fromTop)
- return this;
- });
- cur = cur[cur.length-1];
- var id = cur && cur.length ? cur[0].id : "";
- if (lastId !== id) {
- lastId = id;
- menuItems
- .parent().removeClass("active")
- .end().filter("[href=#"+id+"]").parent().addClass("active");
- }
- });
- // for wordpress memu
- <?php wp_nav_menu( array( 'theme_location' => 'plutin_menu_blog','menu_id' => 'top-navigation', ) ); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement