我有这个按钮,当我单击它时,我想将一个类添加到具有ID的DIV中。之后,它应该滚动到页面底部。
我目前有这个:
$("#signUp").click(function() {
$("#overlay").addClass(".overlay");
$('html, body').animate({scrollBottom:0});
});
HTML:
<div class="big-signup"> <a href="javascript: void(0)" id="signUp"><button>Sign up now. It's <span>FREE »</span></button></a><br /> <br />
和CSS:
#overlay{
height:100%;
width:100%;
display:none;
}
.overlay{
background-color:#000;
opacity:0.5;
}
目前,我无法获得执行任何操作的代码。当我单击按钮时,什么都没有发生。
更新:jsFiddle:http://jsfiddle.net/P23P5/
提前致谢。
最佳答案
addClass方法期望类的名称不带任何点:
$("#overlay").addClass("overlay");
我通常用来将页面滚动到特定位置的代码是:
var target = $(window).height(); // Y value
var animationSelector='html:not(:animated)';
// Fix for Safari
if($.browser.safari) {animationSelector='body:not(:animated)';}
// Animate
$(animationSelector).animate({scrollTop: target}, 400, 'swing');
关于jquery - jQuery-向下滚动并添加覆盖,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9743911/