【发布时间】:2018-01-23 04:47:22
【问题描述】:
该页面有 3 个输入和 3 个内容区域。如果用户在最后一个输入中输入一个值,则所有 3 个内容区域都会更新并变大。然而,其中 2 个在最后一个输入之上,导致用户观看内容“飞”过屏幕。
如何让用户看到相同的输入,然后优雅地滚动到最后一个内容区域
小提琴Here:
<div id="content1">
Content 1
</div>
<div id="content2">
Content 2
</div>
<a href="#" id="videos-link"> CLICK HERE </a>
<div id="content3">
Content 3
</div>
$(document).ready(function() {
$('#videos-link').click(function(event) {
event.preventDefault();
$('#content3').html('loading');
$.ajax({
url: '/echo/js/?js=hello%20world!',
complete: function(response) {
var height = (Math.random() * 1000) + 300;
$('#content1').height(height);
}
});
$.ajax({
url: '/echo/js/?js=hello%20world!',
complete: function(response) {
var height = (Math.random() * 1000) + 300;
$('#content2').delay(200).height(height);
}
});
$.ajax({
url: '/echo/js/?js=hello%20world!',
complete: function(response) {
var height = (Math.random() * 1000) + 300;
$('#content3').html('loading').delay(500).height(height).html('finished loading');
var offsetTop = jQuery("#content3").offset().top - 10;
$('html,body').animate({
scrollTop: offsetTop
}, 1000);
}
});
});
});
在小提琴中,我希望用户继续查看“a”元素,然后在 ajax 请求完成时优雅地滚动到 content3 div。
【问题讨论】:
-
那么你的问题是滚动开头搞砸了,因为它跳转到另一个地方然后开始滚动到element3?
-
差不多了
标签: javascript jquery ajax