forked from mdn/dom-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add onresize event handler example (mdn#86)
* Add resize event example * Add a point about resize-event example * Update README * use addEventListener
- Loading branch information
1 parent
5552351
commit 7642bd3
Showing
2 changed files
with
41 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta name="description" content="A resize event demo on MDN" /> | ||
<title>Window Size Logger</title> | ||
</head> | ||
<body> | ||
<p>Resize the browser window to fire the <code>resize</code> event.</p> | ||
<p>Window height: <span id="height"></span></p> | ||
<p>Window width: <span id="width"></span></p> | ||
|
||
<script> | ||
const heightOutput = document.querySelector("#height"); | ||
const widthOutput = document.querySelector("#width"); | ||
|
||
function resizeListener() { | ||
heightOutput.textContent = window.innerHeight; | ||
widthOutput.textContent = window.innerWidth; | ||
} | ||
|
||
window.addEventListener("resize", resizeListener); | ||
</script> | ||
</body> | ||
</html> |