แอตทริบิวต์ HTML onresize จะทำงานเมื่อผู้ใช้ปรับขนาดหน้าต่างเบราว์เซอร์
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
<tagname onresize=”script”></tagname>
ให้เราดูตัวอย่างของแอตทริบิวต์ HTML onresize เหตุการณ์ -
ตัวอย่าง
<!DOCTYPE html>
<html>
<head>
<style>
body {
color: #000;
height: 100vh;
background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) no-repeat;
padding: 20px;
}
</style>
</head>
<body onresize="resizeFn()">
<h1>HTML onresize Event Attribute Demo</h1>
<p>Now resize the browser window</p>
<script>
function resizeFn() {
document.body.style.background = 'linear-gradient(45deg, #8BC6EC 0%, #9599E2 100%) no-repeat';
}
</script>
</body>
</html> ผลลัพธ์

ตอนนี้ปรับขนาดหน้าต่างเบราว์เซอร์เพื่อดูว่าแอตทริบิวต์ของเหตุการณ์ onresize ทำงานอย่างไร
