[英]Jquery move to other div ( animate )
I have 2 divs: 我有2个div:
CSS 的CSS
#home {
width: 1280px;
height: 1000px;
background: #000;
}
.step1 {
position: absolute;
margin-top: 100px;
margin-left: 500px;
}
.step1 a{
background: #AAF75A;
width: 100%;
line-height: 55px;
padding: 14px 49px;
text-decoration: none;
font-family: tahoma;
font-size: 20px;
}
#about {
position: absolute;
margin-left: 3000px;
width: 1280px;
height: 1000px;
background: #000;
}
HTML 的HTML
<div id="home">
<article>
<div class="step1"><a class="move" href="#about">Let's go</a></div>
</article>
</div>
<div id="about">
<article>
<div class="step1"><a class="move" href="#home">Next !?</a></div>
</article>
</div>
and I want move from div id="home"
to div id="about"
我想从
div id="home"
转到div id="about"
I have this 我有这个
JS JS
$(function($){
$('a.move').click(function() {
var $this = $(this),
_href = $this.attr('href'),
dest = $(_href).offset().top;
$("html:not(:animated),body:not(:animated)").animate({ scrollTop: dest}, 400 );
return false;
});
});
but it just goes down ... it doesn't move to the about div 但是它只是下降了...它不会移动到about div
You have to scroll to the left as well. 您还必须向左滚动。 Like this:
像这样:
$(function ($) {
$('a.move').click(function () {
var $this = $(this),
_href = $this.attr('href'),
destX = $(_href).offset().top;
destY = $(_href).offset().left;
$('body').animate({
scrollTop: destX,
scrollLeft: destY
}, 400);
return false;
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.