JavaScript中的onscroll事件有什么用?
当滚动某个元素的滚动条时,将发生onscroll事件。您可以尝试运行以下代码,以了解如何在JavaScript中实现onscroll 事件。
示例
<!DOCTYPE html>
<html>
<head>
<style>
div {
border: 2px solid blue;
width: 300px;
height: 100px;
overflow: scroll;
}
</style>
</head>
<body>
<div id="content">
This is demo text. This is demo text.This is demo text.This is demo text.
This is demo text.This is demo text.This is demo text.This is demo text.
This is demo text.This is demo text.This is demo text.
This is demo text.This is demo text.This is demo text.
This is demo text.This is demo text.This is demo text.
</div>
<p id = "myScroll"> </p>
<script>
document.getElementById("content").onscroll = function() {myFunction()};
function myFunction() {
document.getElementById("myScroll").innerHTML = "Scroll successfull!.";
}
</script>
</body>
</html>热门推荐
10 老爸生日暴富祝福语简短
11 女神节日简短祝福语大全
12 六一互换礼物祝福语简短
13 妈妈祝福语简短16字
14 身体康复的祝福语简短
15 生女儿的祝福语简短
16 发小结婚简短祝福语
17 对航母的祝福语简短
18 祝寿时祝福语简短精辟