-1
下面的Javascript有什么作用?有人能解释一下这个平滑的滚动API中的每一行吗?NoobProgramer =“需要对此JQUERY平滑滚动代码进行解释”
$('a').click(function(){ //when you click 'a' run this function
$('html, body').animate({ // animate what is in the html and body?
scrollTop: $($(this).attr('href')).offset().top //grab coordinates?
}, 800); // scroll speed?
return false; // not sure what this means
});
'返回false;'取消点击动作。关于animate的文档:http://api.jquery.com/animate/ jquery多选择器https://api.jquery.com/multiple-selector/ – epascarello
几乎所有的好东西......'$('html,body')'是DOM选择器(我认为HTML不包括在内)......并且“返回false”会阻止“a”按预期工作(当您单击“a”元素时,您正在执行自定义行为,所以您不需要默认行为) – Hackerman
'return false'与'function(ev){ev.preventDefault();'相同,就像@epascarello所说的那样,只是当你点击链接时它不会重定向到'href =“”' – Baruch