[英]Debounce html document height on content change
Assume the viewport is 100×100 (width × height) , the document is empty, the scroll position is (0,0) (x,y) . 假设视口为100×100 (宽×高) ,文档为空,滚动位置为(0,0) (x,y) 。
body.appendChild
an element A of size 100×200 body.appendChild
元素A的大小为100×200 body.appendChild
s B (100×50) body.appendChild
的B(100×50) body.appendChild
s C (100×200 again) body.appendChild
的C(再次为100×200) Now the browser is still scrolled at 0,0. 现在浏览器仍在0,0滚动。 I'm looking for a solution/library/jQueryPlugin (nothing that i have to insert at 3 and 6) to prevent (4) from happening for a custom defined threshold (in this case ~150ms).
我正在寻找解决方案/库/ jQueryPlugin(无需在3和6插入任何内容),以防止自定义阈值(在这种情况下为150ms)发生(4)。
this fiddle blocks the scrollbar for 500 seconds when the height of the element changes 当元素的高度改变时,这个小提琴会阻塞滚动条500秒
$(document).on('click', function(e) {
var elementClone = $('.element').clone();
var currentHeight = $('.element').height();
var currentWinHeight = $(document).height();
$('body, html').css({
height: currentHeight
});
$('.element').remove();
var randomHeight = Math.random() * 1000;
elementClone.css({
height: randomHeight
}).text('height: ' + randomHeight).appendTo('body');
window.setTimeout( function() {
$('body, html').css({
height: 'auto'
});
}, 500)
e.preventDefault();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.