[英]Scroll to the top of a DIV using JavaScript/jQuery?
I have a <div>
popup that is shown when a link is clicked. 单击链接后会显示一个
<div>
弹出窗口。 It has scrollable content if there is overflow. 如果有溢出,它具有可滚动的内容。
I just need to have the <div>
at the top of the scrollable area if the link is clicked again. 如果再次单击链接,我只需要在可滚动区域的顶部放置
<div>
。 This is working perfectly in Chrome and Firefox, however in IE, it remains scrolled to the bottom of the popup. 这在Chrome和Firefox中可以完美运行,但是在IE中,它仍然滚动到弹出窗口的底部。
<div id="myModal" data-role="popup" data-position-to="window" data-history="false" data-theme="a" data-corners="true" class="ui-content" style="text-align:center">
<div class="modal-dialog">
<div class="modal-content">
<div id='myModalContent'></div>
<a href="#" id="closeButton" class="ui-btn ui-corner-all ui-shadow ui-btn-inline ui-btn-b">OK</a>
</div>
</div>
</div>
$(".anchorDetail").click(function () {
$("#myModal").scrollTop(0);
}
Try this, it's done with JS and not jQuery: 试试看,它是用JS而不是jQuery完成的:
document.querySelector('.anchorDetail').addEventListener('click', function() {
var myDiv = document.getElementById('myModal');
myDiv.scrollTop = 0;
});
Thank you all for your suggestions. 谢谢大家的建议。
I feel so so dumb. 我好傻
I was having it attempt to scroll to the top before it populated the data and opened the popup. 我试图让它滚动到顶部,然后再填充数据并打开弹出窗口。
I moved the .scrollTop() function to after i Open the popup, and VOILA. 打开弹出窗口和VOILA之后,将.scrollTop()函数移至。
Thank you all again. 再次谢谢大家。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.