2014-10-06 64 views
0

知道我怎麼可以添加資產時,每個格滾動下拉菜單添加活性滾動我想

$(".link").click(function() { 
     $('html, body').animate({ 
      scrollTop: $($.attr(this, 'href')).offset().top 
     }, 500); 
     return false; 
    }); 

鏈接:http://jsfiddle.net/r8325qy8/

+0

你怎麼加的資產是什麼意思? – kfirba 2014-10-06 20:43:24

+0

http://jsfiddle.net/r8325qy8/1/例如:http://screencast.com/t/5mO8UxWO – Raul 2014-10-06 20:46:49

+0

你想標記當前點擊的元素?所以當點擊品牌時,它會變成黃色,Nosotros會變成白色? – kfirba 2014-10-06 20:49:22

回答

0

你可以做到這一點通過去除.current類任何其他元素並將該類添加到被單擊的目標。

$(".link").click(function() { 

      var target = $(this); // select the current clicked element 

      $('html, body').animate({ 
       scrollTop: $($.attr(this, 'href')).offset().top 
      }, 500, function() { 
       $('li.current').removeClass('current'); // remove all previous marking 
       target.parent().addClass('current'); // apply the css class to the clicked element 
      }); 
      return false; 
     }); 

A working fiddle