0
<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {
height: 250px;
width: 250px;
overflow: auto;
}
#content {
height: 800px;
width: 2000px;
background-color: coral;
}
</style>
</head>
<body>
<p>Scroll inside the div element to display the number of pixels the content of div is scrolled horizontally and vertically.</p>
<div id="myDIV">
<div id="content">Scroll inside me!</div>
</div>
<p id="demo"></p>
<script>
document.getElementById("myDIV").addEventListener('scroll', function (e) {
alert("scroll");
});
document.getElementById("myDIV").addEventListener('click', function (e) {
alert("click");
});
</script>
爲什麼它不是在工作IE我在W3起到相同的代碼自己嘗試一下頁面,它工作在IE但如果我嘗試它作爲一個單獨的文件,如此混亂。即使有人贊成這個,請告訴我我錯過了什麼?
我發現這些東西,當我瀏覽其他答案:
- 指着window.scroll但我需要一個特定元素
- 使用溢出-X:滾動;溢出-y:隱藏; 。反之亦然(沒有工作,也是我需要滾動兩種方式)
注:
此代碼的工作顯然在其他瀏覽器。