试图滚动到div并且持续时间不起作用,我是jquery的新手所以我认为我在某处有一个愚蠢的错误?我想要了解更多按钮,向下滚动到id =“more”的div。
感谢您的帮助
JS
$(document).ready(function()
{
$('#learn-more-button').localScroll({
duration: 5000,
target:'#more'
});
});
HTML
<div class="page1_wrapper">
<div class="page1">
<nav class="navigation">
<ul>
<li>Home</li>
<li>Support</li>
<li>Sign Up</li>
<li>Contact</li>
</ul>
</nav>
</div>
<div class="page1-content centered">
<h1> Generic Header</h1>
<h2> Generic Content 1</h2>
<h2> Generic Content 2</h2>
<h2> Generic Content 3</h2>
</div>
<div id="learn-more-button" class="learn-more centered">
<a href="#more"> learn more </a>
</div>
</div>
<div id="more" class="scroller">
<div class="page2-content">
<p> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,</p>
</div>
</div>
CSS
body, html{
width:100%;
height:100%;
padding:0px;
margin:0px;
}
.page1_wrapper {
height:100%;
width:100%;
overflow:hidden;
border:1px solid red; /* just needed to show the size auf the div */
}
.centered {
margin: 0px auto;
position: relative;
vertical-align: middle;
text-align: center;
}
nav {
list-style: none;
}
.navigation ul li {
list-style: none;
float:left;
margin: 5px;
}
.page1-content {
clear:both;
}
.learn-more a {
color:red;
}
.page2-content {
margin: 0px 0 auto;
background-color: white;
color: black;
background-size: 100% 1000px;
}
.scroller{
position: relative;
overflow: hidden;
height: 410px;
width: 787px;
}
答案 0 :(得分:1)
看看Demo Fiddle如何实现这一点。 希望它会对你有所帮助。
这是一个剧本。
$(document).ready(function (){
$("#click").click(function (){
//$(this).animate(function(){
$('html, body').animate({
scrollTop: $("#text").offset().top
}, 2000);
//});
});
});