我的两个Jquery脚本互相干扰

时间:2018-06-03 02:52:22

标签: javascript jquery

我该怎么做才能使用这两种功能?

第一个是:

jQuery(document).ready(function() {
  jQuery('.toggle-nav').click(function(e) {
    jQuery(this).toggleClass('active');
    jQuery('.menu ul').toggleClass('active');
    e.preventDefault();  
  });
}); 

第二个是:

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

使用这两个脚本的正确语法是什么?谢谢!

1 个答案:

答案 0 :(得分:0)

错误地使用attr()。尝试更改

scrollTop: $( $.attr(this, 'href') ).offset().top

scrollTop: $( $(this).attr('href') ).offset().top

如果仍有问题,请检查浏览器开发工具控制台是否存在任何错误

相关问题