比方说,我有这样的情况:保持页面的位置,同时页面长度变化
- 的页面是4000个像素长。
- 用户向下滚动页面,因此1000个像素的内容隐藏在视口上方。
然后,用户点击一个按钮,和任意长度的内容经由AJAX加载在页面的顶部,按下按钮(和该内容的用户在看)视口的下方。
我试着写了一个Javascript回调向下滚动到用户在点击按钮之前查看的内容,但体验并不是无缝的(当插入新内容后滚动“向上”,然后是向下滚动“向下”)。
有没有什么办法让视口固定在用户正在看的内容上?
这是一个简化的例子,但应该得到重点。
<div style="height: 1000px; width:1000px;" id="top-div">some content above the fold</div>
<button id="button">Click Me</button>
<img src="img.jpg" alt="Some image the user was looking at when they clicked the button." />
<script>
$("button").click(function() {
$.get('/new/content', function(response) {
$("#top-div").before(response);
});
});
</script>
如何开始工作小提琴,所以我们不必自己设置整个东西? :) –
在正在查看的内容下添加新内容。 – kennebec
在这种情况下不是一个选项... –