好吧,我无法解决这个问题。这是问题所在。
我在页面加载时有scrollTop Jquery,在延迟后滚动页面以供用户采取操作。但是在点击“#b3,#b3b”按钮后,我无法让另一个scrollTop工作,延迟后滚动到页面底部。
它应该滚动到底部的.comp元素,但它不会或只是向下滚动。
有人能告诉我如何在点击按钮后第二次滚动到底部元素?
$(document).ready(function () {
$('html, body').delay(1500).animate({
scrollTop: $('.button').offset().top
}, 'slow');
$("#b1,#b1b").click(function(){
$("#a1").fadeOut('fast'),$("#a2").fadeIn('slow');
});
$("#b2,#b2b").click(function(){
$("#a2").fadeOut('fast'),$("#a3").fadeIn('slow');
});
$("#b3,#b3b").click(function(){
$("#a3").fadeOut('fast'),$("#a4").fadeIn('slow');
$("#bar").width(0);
$("#bar").delay(150).animate({width: '+=40%'},'slow').delay(1200).animate({width: '+=20%'},'slow').delay(1000).animate({width: '+=20%'},'slow').delay(2000).animate({width: '+=20%'},'slow');
$('html, body').delay(10000).animate({
scrollTop: $('.comp').offset().top
}, 'slow');
$('#r1').show(500).delay(2000).hide(500);
$('#r2').delay(2000).show(500).delay(2000).hide(500);
$('#r3').delay(4500).show(500).delay(2000).hide(500);
$('#r4').delay(7000).show(500);
$('#r5').delay(8500).show(500);
$('#rb1').delay(2000).show(500);
$('#rb2').delay(4500).show(500);
$('#rb3').delay(7500).show(500);
});
});
* {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
p,h1,h2,h3,h4,h5{
padding-bottom: 1em;
}
body {
background-color: #000;
color: #FFF;
}
img {
margin: 0px;
padding: 0px;
display: block;
}
#wrap {
max-width: 1000px;
margin: 10px;
border: 1px solid #333;
background-color: #292929;
padding: 10px;
border-radius: 8px;
-moz-border-radius: 8px;
-webkit-border-radius: 8px;
}
#header {
font-family: Roboto, Helvetica, Arial, sans-serif;
font-size: 1.6em;
text-align: center;
}
#content {
}
#graphic {
}
#graphic img {
width: 90%;
height: auto;
max-width: 400px;
display: block;
margin: auto;
padding: 5px;
border: 1px solid #525252;
background-color: #3C3C3C;
}
#text {
margin-top: 15px;
}
#text p {
font-family: Arial, Helvetica, sans-serif;
font-size: 0.9em;
text-align: center;
line-height: 1.2em;
}
#javascript_countdown_time {
font-weight: bold;
color: #F60;
}
.actionbox {
border-top-width: 1px;
border-right-width: 0px;
border-bottom-width: 0px;
border-left-width: 0px;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
border-top-color: #999;
border-right-color: #999;
border-bottom-color: #999;
border-left-color: #999;
padding-top: 20px;
}
.actionbox h2 {
clear: both;
display: block;
font-family: Roboto, Helvetica, Arial, sans-serif;
font-size: 1.3em;
font-weight: 300;
line-height: 1.1em;
}
.actionbox h2 strong {
font-weight: bold;
}
.actionbox h3 {
font-family: Helvetica, Roboto, Tahoma, sans-serif;
font-weight: bold;
font-size: 1em;
color: #F90;
}
.actionbox h4 {
text-align: center;
font-size: 1em;
font-weight: bold;
font-family: Arial, Helvetica, sans-serif;
padding-top: 30px;
}
.actionbox ul {
margin-left: 10px;
margin-top: 20px;
}
.actionbox ul li{
background-repeat: no-repeat;
list-style-type: none;
padding-left: 30px;
background-size: 20px;
padding-bottom: 1em;
background-position: left top;
padding-top: 3px;
font-family: Arial, Helvetica, sans-serif;
font-size: 0.9em;
}
.actionbox ol {
margin-left: 30px;
}
.actionbox ol li {
padding-bottom: 1em;
font-family: Roboto, Helvetica, Arial, sans-serif;
font-size: 0.9em;
}
.butbox {
display: table;
width: 100%;
table-layout: fixed;
}
.butbox .button, .butbox .buttonr {
display: table-cell;
}
.button a{
text-decoration: none;
text-shadow: 1px 1px 0 rgba(0,0,0,0.3);
background-color: #00CB00;
background-image: -webkit-gradient(linear, left top, left bottom, from(#00CB00), to(#009A00));
background-image: -webkit-linear-gradient(top, #00CB00, #009A00);
background-image: -moz-linear-gradient(top, #00CB00, #009A00);
background-image: -ms-linear-gradient(top, #00CB00, #009A00);
background-image: -o-linear-gradient(top, #00CB00, #009A00);
background-image: linear-gradient(to bottom, #00CB00, #009A00);
filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=#00CB00, endColorstr=#009A00);
display: block;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
border-top-width: 0px;
border-right-width: 2px;
border-bottom-width: 0px;
border-left-width: 0px;
border-top-color: #292929;
border-right-color: #292929;
border-bottom-color: #292929;
border-left-color: #292929;
-webkit-border-top-left-radius:5px;
-moz-border-radius-topleft:5px;
border-top-left-radius:5px;
-webkit-border-top-right-radius:0px;
-moz-border-radius-topright:0px;
border-top-right-radius:0px;
-webkit-border-bottom-right-radius:0px;
-moz-border-radius-bottomright:0px;
border-bottom-right-radius:0px;
-webkit-border-bottom-left-radius:5px;
-moz-border-radius-bottomleft:5px;
border-bottom-left-radius:5px;
}
.button a:hover {
background-color: #009800; background-image: -webkit-gradient(linear, left top, left bottom, from(#009800), to(#006700));
background-image: -webkit-linear-gradient(top, #009800, #006700);
background-image: -moz-linear-gradient(top, #009800, #006700);
background-image: -ms-linear-gradient(top, #009800, #006700);
background-image: -o-linear-gradient(top, #009800, #006700);
background-image: linear-gradient(to bottom, #009800, #006700);filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=#009800, endColorstr=#006700);
}
.buttonr a {
text-decoration: none;
text-shadow: 1px 1px 0 rgba(0,0,0,0.3);
background-color: #CC0000;
background-image: -webkit-gradient(linear, left top, left bottom, from(#CC0000), to(#9b0000));
background-image: -webkit-linear-gradient(top, #CC0000, #9b0000);
background-image: -moz-linear-gradient(top, #CC0000, #9b0000);
background-image: -ms-linear-gradient(top, #CC0000, #9b0000);
background-image: -o-linear-gradient(top, #CC0000, #9b0000);
background-image: linear-gradient(to bottom, #CC0000, #9b0000);
filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=#CC0000, endColorstr=#9b0000);
border-top-width: 0px;
border-right-width: 0px;
border-bottom-width: 0px;
border-left-width: 2px;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
border-top-color: #292929;
border-right-color: #292929;
border-bottom-color: #292929;
border-left-color: #292929;
display: block;
-webkit-border-top-left-radius:0px;
-moz-border-radius-topleft:0px;
border-top-left-radius:0px;
-webkit-border-top-right-radius:5px;
-moz-border-radius-topright:5px;
border-top-right-radius:5px;
-webkit-border-bottom-right-radius:5px;
-moz-border-radius-bottomright:5px;
border-bottom-right-radius:5px;
-webkit-border-bottom-left-radius:0px;
-moz-border-radius-bottomleft:0px;
border-bottom-left-radius:0px;
}
.buttonr a:hover{
background-color: #990000; background-image: -webkit-gradient(linear, left top, left bottom, from(#990000), to(#680000));
background-image: -webkit-linear-gradient(top, #990000, #680000);
background-image: -moz-linear-gradient(top, #990000, #680000);
background-image: -ms-linear-gradient(top, #990000, #680000);
background-image: -o-linear-gradient(top, #990000, #680000);
background-image: linear-gradient(to bottom, #990000, #680000);filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=#990000, endColorstr=#680000);
}
.buttxt a{
text-align: center;
padding: 5px;
font-family: Roboto, Helvetica, Arial, sans-serif;
font-size: 2em;
text-decoration: none;
color: #FFF;
}
.buttonlast a {
text-decoration: none;
text-shadow: 1px 1px 0 rgba(0,0,0,0.3);
background-color: #00CB00;
background-image: -webkit-gradient(linear, left top, left bottom, from(#00CB00), to(#009A00));
background-image: -webkit-linear-gradient(top, #00CB00, #009A00);
background-image: -moz-linear-gradient(top, #00CB00, #009A00);
background-image: -ms-linear-gradient(top, #00CB00, #009A00);
background-image: -o-linear-gradient(top, #00CB00, #009A00);
background-image: linear-gradient(to bottom, #00CB00, #009A00);
filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=#00CB00, endColorstr=#009A00);
display: block;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
border-top-width: 0px;
border-right-width: 2px;
border-bottom-width: 0px;
border-left-width: 0px;
border-top-color: #292929;
border-right-color: #292929;
border-bottom-color: #292929;
border-left-color: #292929;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
margin-top: 10px;
}
.buttonlast a:hover {
background-color: #009800;
background-image: -webkit-gradient(linear, left top, left bottom, from(#009800), to(#006700));
background-image: -webkit-linear-gradient(top, #009800, #006700);
background-image: -moz-linear-gradient(top, #009800, #006700);
background-image: -ms-linear-gradient(top, #009800, #006700);
background-image: -o-linear-gradient(top, #009800, #006700);
background-image: linear-gradient(to bottom, #009800, #006700);
filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=#009800, endColorstr=#006700);}
.comp {
padding-top: 20px;
padding-bottom: 20px;
font-family: Arial, Helvetica, sans-serif;
font-size: 0.7em;
text-align: center;
}
#bar {
background-color: #3C0;
border-top-style: none;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
height: 30px;
width: 100%;
margin-bottom: 15px;
}
#percentage {
font-family: Arial, Helvetica, sans-serif;
font-size: 0.9em;
text-align: center;
line-height: 30px;
}
.orange {
color: #F60;
}
#a2,#a3,#a4,#rb1,#r2,#rb2,#r3,#rb3,#r4,#r5 {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="wrap">
<div id="header"><h1>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. </h1>
</div>
<div id="content">
<div id="graphic"><img src="#" alt="" height="500px" width="300px"></div>
<div id="text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. Sed lectus. Integer euismod lacus luctus magna. Quisque cursus, metus vitae pharetra auctor, sem massa mattis sem, at interdum magna augue eget diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi lacinia molestie dui. Praesent blandit dolor. Sed non quam. In vel mi sit amet augue congue elementum. Morbi in ipsum sit amet pede facilisis laoreet. Donec lacus nunc, viverra nec.</p>
<div class="actionbox" id="a3" style="display:block">
<h2><strong>Question 3:</strong></h2>
<div class="butbox">
<div class="button buttxt" id="b3"><a href="#/">YES</a></div>
<div class="buttonr buttxt" id="b3b"><a href="#/">NO</a></div>
</div>
</div>
<div class="actionbox" id="a4">
<div id="bar"><div id="percentage"></div></div>
<h3 id="r1">step1...</h3>
<h3 id="r2">step2...</h3>
<h3 id="r3">step3...</h3>
<h3 id="r4">step4...</h3>
<ul>
<li id="rb1">xxx</li>
<li id="rb2">xxx</li>
<li id="rb3">xxx</li>
</ul>
<div id="r5" class="congrats">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. Sed lectus. Integer euismod lacus luctus magna. Quisque cursus, metus vitae pharetra auctor, sem massa mattis sem, at interdum magna augue eget diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi lacinia molestie dui. Praesent blandit dolor. Sed non quam. In vel mi sit amet augue congue elementum. Morbi in ipsum sit amet pede facilisis laoreet. Donec lacus nunc, viverra nec.
<div class="buttonlast buttxt"><a href="#/">I AGREE</a></div>
<div class="comp">xxxx</div>
</div>
</div>
</div>
</div>
</div>
答案 0 :(得分:1)
不是试图在绝对时间内延迟动画,而是通过嵌套在另一个动画完成时执行的函数,使它们彼此相对。这样你也可以相对确定滚动到的元素在正确的时间到来时将是非隐藏的(我认为这是你的问题)。
请参阅this fiddle。
我把时间搞得一团糟,但它应该给你一个想法。改变后的代码现在看起来像这样:
$("#b3,#b3b").click(function(){
$("#a3").fadeOut('fast'),$("#a4").fadeIn('slow');
$("#bar").width(0);
$('#r1').show(500);
$("#bar").delay(150).animate({width: '+=40%'},2000, function() {
$('#r1').hide(500);
$('#r2').show(500);
$('#rb1').show(500);
$("#bar").animate({width: '+=20%'},2000, function() {
$('#r2').hide(500);
$('#r3').show(500);
$('#rb2').show(500);
$("#bar").animate({width: '+=20%'},2000, function() {
$('#r3').hide(500);
$('#r4').show(500);
$('#rb3').show(500);
$("#bar").animate({width: '+=20%'},2000, function() {
$('#r4').show(500);
$("#r5").show(); // show the element before you scroll to its child
$('html, body').animate({
scrollTop: $('.comp').offset().top
}, 'slow');
});
});
});
});
});