pro*_*est 2 html syntax jquery slide
所以我试图做到这一点,然后当你点击旋转木马中的一个链接时,它会将你向下滚动到页面内容.
这是我的jquery:
$('#picks li a').click(function(){
$('html, body').animate({
scrollTop: $( $.attr(this, 'href') ).offset().top
}, 500);
return false;
});
Run Code Online (Sandbox Code Playgroud)
但是我在我的控制台中收到此错误错误:语法错误,无法识别的表达式:http://hutchcreative.co.uk/rod/other/#galleryDetails
这是正确的链接位置,但不知道如何纠正它,以便jquery添加幻灯片?
谢谢!
如果属性href引用元素的id,则需要使用#actuall ID之前的值
$('#picks li a').click(function(){
$('html, body').animate({
scrollTop: $( '#'+$.attr(this, 'href') ).offset().top
}, 500);
return false;
});
Run Code Online (Sandbox Code Playgroud)
另请注意,这将被触发两次; 我知道你为了使用firefox 而添加了html,因为我有一段时间了,
所以你可以:
$('#picks li a').click(function(){
$(Query.browser.mozilla ? "html" : "body").animate({
scrollTop: $( '#'+$.attr(this, 'href') ).offset().top
}, 500);
return false;
});
Run Code Online (Sandbox Code Playgroud)
或者,至少在之前停止动画:
$('#picks li a').click(function(){
$('html, body').stop(true,true).animate({
scrollTop: $( '#'+$.attr(this, 'href') ).offset().top
}, 500);
return false;
});
Run Code Online (Sandbox Code Playgroud)
为了防止这个双重调用的一些问题