![](/img/trans.png)
[英]How can I create a function so that the content in a modal window scrolls to top when body prevents scroll?
[英]How can I read scrolls on an open modal window?
元素上的scrollY將不起作用。
您可以使用Element的scrollTop
(垂直滾動元素內容的像素數)
.modal{ position: absolute; width: 50%; left: 25%; top: 15%; height: 80%; border: 2px solid black; overflow-y: auto; }
<span id="result"></span> <div class="modal" id="modal"> Header <span style="position: relative; top: 500px;">Footer</span> </div> <script> document.getElementById("modal").onscroll = function (e) { document.getElementById('result').textContent = "Number of pixels scrolled vertically: "+document.getElementById("modal").scrollTop; }; </script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.