Якоря в NavBar
Всем привет, делаю NavBar на сайте, воткнул такой код:
var menu_selector = "#navbar-list-wrap"; // Переменная должна содержать название класса или идентификатора, обертки нашего меню. function onScroll(){ var scroll_top = $(document).scrollTop(); $(menu_selector + " a").each(function(){ var hash = $(this).attr("href"); var target = $(hash); if (target.position().top <= scroll_top && target.position().top + target.outerHeight() > scroll_top) { $(menu_selector + " a.active").removeClass("active"); $(this).addClass("active"); } else { $(this).removeClass("active"); } }); } $(document).ready(function () { $(document).on("scroll", onScroll); $('a[href*=\\#]:not([href=\\#])').click(function(e){ e.preventDefault(); $(document).off("scroll"); $(menu_selector + " a.active").removeClass("active"); $(this).addClass("active"); var hash = $(this).attr("href"); var target = $(hash); $("html, body").animate({ scrollTop: target.offset().top }, 800, function(){ window.location.hash = hash; $(document).on("scroll", onScroll); }); }); }); Ссылки с конкретными href типа #home ведет на блок id="home". Проблема в том что все ссылки с решеткой стали мотать по страницы в рандомное место и возвращать обратно, как поправить? |
Решил, выставил $('a[href*=\\.]:not([href=\\.])').click(function(e){
Cделал перемещение не по id а по классу |
Сказали по классу нельзя, как быть?
|
Часовой пояс GMT +3, время: 06:18. |