-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(html): update srcset-resolutions demo (#694)
- related to mdn/content#3397 The PR - adds script to show actual loaded image name on screen - runs Prettier on the file On touch devices developer tools are not available. The change makes easy to realize which image has been fetched and loaded by the browser.
- Loading branch information
1 parent
1721dd5
commit 558306e
Showing
1 changed file
with
26 additions
and
14 deletions.
There are no files selected for viewing
40 changes: 26 additions & 14 deletions
40
html/multimedia-and-embedding/responsive-images/srcset-resolutions.html
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 |
---|---|---|
@@ -1,25 +1,37 @@ | ||
<!DOCTYPE html> | ||
<!doctype html> | ||
<html lang="en-us"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width"> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width" /> | ||
<title>Responsive HTML images demo</title> | ||
<style> | ||
|
||
img { | ||
width: 320px; | ||
} | ||
|
||
</style> | ||
</head> | ||
<body> | ||
|
||
|
||
<img srcset="elva-fairy-320w.jpg, | ||
elva-fairy-480w.jpg 1.5x, | ||
elva-fairy-640w.jpg 2x" | ||
src="elva-fairy-640w.jpg" alt="Elva dressed as a fairy"> | ||
|
||
|
||
<img | ||
srcset=" | ||
elva-fairy-320w.jpg, | ||
elva-fairy-480w.jpg 1.5x, | ||
elva-fairy-640w.jpg 2x | ||
" | ||
src="elva-fairy-640w.jpg" | ||
alt="Elva dressed as a fairy" | ||
id="img" | ||
onload="showUrl()" | ||
/> | ||
<script> | ||
function showUrl() { | ||
const img = document.getElementById("img"); | ||
const p = document.createElement("p"); | ||
const fileName = img.currentSrc?.substring( | ||
img.currentSrc.lastIndexOf("/"), | ||
); | ||
p.textContent = `Loaded: ${fileName}`; | ||
document.body.appendChild(p); | ||
} | ||
</script> | ||
</body> | ||
</html> | ||
</html> |