HTMLonscrollイベント属性
HTML onscrollイベント属性は、HTMLドキュメントでスクロールバーを使用してHTML要素がスクロールされたときにトリガーされます。
構文
以下は構文です-
<tagname onscroll=”script”></tagname>
HTMLonscrollイベント属性の例を見てみましょう-
例
<!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;
}
.box-para {
border: 2px solid #fff;
padding: 10px;
width: 200px;
height: 200px;
overflow: scroll;
margin: 1rem auto;
}
</style>
</head>
<body>
<h1>HTML onscroll Event Attribute Demo</h1>
<p onscroll="scrollFn()" class="box-para">
This is a paragraph element with some dummy text. This is a paragraph element with some dummy text.
This is a paragraph element with some dummy text. This is a paragraph element with some dummy text.
This is a paragraph element with some dummy text. This is a paragraph element with some dummy text.
This is a paragraph element with some dummy text. This is a paragraph element with some dummy text.
This is a paragraph element with some dummy text. This is a paragraph element with some dummy text.
This is a paragraph element with some dummy text. This is a paragraph element with some dummy text.
This is a paragraph element with some dummy text. This is a paragraph element with some dummy text.
This is a paragraph element with some dummy text.</p>
<p>Scroll above paragraph text to increase its font size</p>
<script>
function scrollFn() {
document.querySelector(".box-para").style.fontSize = "1.5rem";
}
</script>
</body>
</html> 出力
段落の内容をスクロールして、onscrollイベント属性がどのように機能するかを確認します-
-
HTMLオンドロップイベント属性
HTML ondropイベント属性は、ドラッグ可能な要素またはテキストがHTMLドキュメントの有効なドロップターゲットにドロップされたときにトリガーされます。 構文 以下は構文です- <tagname ondrop=”script”></tagname> HTMLオンドロップイベント属性の例を見てみましょう- 例 <!DOCTYPE html> <html> <head> <style> body { color: #000;
-
HTMLondragleaveイベント属性
HTML ondragleaveイベント属性は、ドラッグ可能な要素またはテキストがHTMLドキュメントの有効なドロップターゲットを終了したときにトリガーされます。 構文 以下は構文です- <tagname ondragleave=”script”></tagname> HTMLのondragleaveイベント属性の例を見てみましょう- 例 <!DOCTYPE html> <html> <head> <style> body {