@sashavol

Не поймать событие клика у меню?

Добрый вечер!
Мучаюсь чтобы поймать клик, хочу приделать scrollspy, но банально не взять клик, вот сам сайт:
https://turisol.net/dev1/index.php?option=com_jomr...
(конкретно желтое меню, если по скролить ниже)

Пытался и по дата атрибутам, там мутулс установлен, и естественно через noconflict делаю, 0 результата. Подскажите куда пожалуйста куда двигаться.

Мой код:
var lastId,
    topMenu = jQuery(".nav-tabs"),
    topMenuHeight = topMenu.outerHeight()+15,
    // All list items
    menuItems = topMenu.find('a'),
    // Anchors corresponding to menu items
    scrollItems = menuItems.map(function(){
      var item = jQuery(jQuery(this).attr("href"));
      if (item.length) { return item; }
    });
console.log(scrollItems);
// Bind click handler to menu items
// so we can get a fancy scroll animation
menuItems.click(function(e){
	console.log("Click");
  var href = jQuery(this).attr("href"),
      offsetTop = href === "#" ? 0 : jQuery(href).offset().top-topMenuHeight+1;
  jQuery('html, body').stop().animate({ 
      scrollTop: offsetTop
  }, 300);
  e.preventDefault();
});

// Bind to scroll
jQuery(window).scroll(function(){
   // Get container scroll position
   var fromTop = jQuery(this).scrollTop()+topMenuHeight;
   
   // Get id of current scroll item
   var cur = scrollItems.map(function(){
     if (jQuery(this).offset().top < fromTop)
       return this;
   });
   // Get the id of the current element
   cur = cur[cur.length-1];
   var id = cur && cur.length ? cur[0].id : "";
   
   if (lastId !== id) {
       lastId = id;
       // Set/remove active class
       menuItems
         .parent().removeClass("active")
         .end().filter("[href=#"+id+"]").parent().addClass("active");
   }                   
});

// end scroll spy
  • Вопрос задан
  • 195 просмотров
Решения вопроса 1
@OVK2015
jQuery(".nav-tabs a").bind("click", function(event){alert(this); event.preventDefault;})

Мне вот это
хочу приделать scrollspy, но банально не взять клик
не понятно. Что вы хотите сделать?
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы