HTMLオンホイールイベント属性
HTML onwheelイベント属性は、ユーザーがHTMLドキュメントのHTML要素上でマウスのホイールを動かすとトリガーされます。
構文
以下は構文です-
<tagname onwheel=”script”>Content</tagname>
HTMLオンホイールイベント属性の例を見てみましょう-
例
<!DOCTYPE html>
<html>
<head>
<style>
body {
color: #000;
height: 100vh;
background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) no-repeat;
text-align: center;
padding: 20px;
}
.wheel {
border: 2px solid #fff;
padding: 10px;
}
</style>
</head>
<body>
<h1>HTML onwheel Event Attribute Demo</h1>
<p onwheel='wheelFn()' class='wheel'>This is a paragraph with some dummy content.
This is a paragraph with some dummy content. This is a paragraph with some dummy content.
This is a paragraph with some dummy content. This is a paragraph with some dummy content.
This is a paragraph with some dummy content. This is a paragraph with some dummy content.
This is a paragraph with some dummy content.</p>
<p>Move the wheel of the mouse up or down on above paragraph</p>
<script>
function wheelFn() {
document.body.style.background = "linear-gradient(45deg, #8BC6EC 0%, #9599E2 100%) no-repeat";
document.body.style.color = "#fff";
}
</script>
</body>
</html> 出力
次に、段落要素上でマウスホイールを上下に動かして、onwheelイベント属性がどのように機能するかを観察します。
-
HTMLondragstartイベント属性
HTML ondragstartイベント属性は、ユーザーがHTML要素またはHTMLドキュメント内の要素のテキストのドラッグを開始したときにトリガーされます。 構文 以下は構文です- <tagname ondragstart=”script”></tagname> HTMLのondragstartイベント属性の例を見てみましょう- 例 <!DOCTYPE html> <html> <head> <style> body { co
-
HTMLオンドロップイベント属性
HTML ondropイベント属性は、ドラッグ可能な要素またはテキストがHTMLドキュメントの有効なドロップターゲットにドロップされたときにトリガーされます。 構文 以下は構文です- <tagname ondrop=”script”></tagname> HTMLオンドロップイベント属性の例を見てみましょう- 例 <!DOCTYPE html> <html> <head> <style> body { color: #000;