當滑鼠滾輪在 HTML 中某個元素上向上或向下滾動時執行指令碼?
當滑鼠滾輪在某個元素上向上或向下滾動時,onwheel 屬性觸發。您可以嘗試執行以下程式碼來實現onwheel 屬性 −
示例
<!DOCTYPE html>
<html>
<body>
<h3 id = "myid" onwheel = "mouseWheel()">
This is demo heading.
</h3>
<p>Click above and use mouse wheel to change the heading color.</p>
<script>
function mouseWheel() {
document.getElementById("myid").style.color = "red";
}
</script>
</body>
</html>
廣告
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP