Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update srcset-resolutions.html #696

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,67 @@
<html lang="en-us">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<meta content="width=device-width" name="viewport" />
<title>Responsive HTML images demo</title>
<style>
img {
width: 320px;
}
figure {
display: inline-flex;
flex-flow: column;
margin: 0.5rem;
}

figcaption {
background-color: #222;
color: #fff;
font: italic smaller sans-serif;
padding: 3px;
text-align: center;
}
</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"
id="img"
onload="showUrl()"
/>
<script>
function showUrl() {
const img = document.getElementById("img");
const p = document.createElement("p");
const caption = document.querySelector(".caption");
const fileName = img.currentSrc?.substring(
img.currentSrc.lastIndexOf("/"),
);
p.textContent = `Loaded: ${fileName}`;
document.body.appendChild(p);
caption.textContent = `Loaded: ${fileName}`;
}
</script>
</head>
<body>
<figure>
<figcaption class="caption"></figcaption>
<img
alt="Elva dressed as a fairy"
id="img"
onload="showUrl()"
src="elva-fairy-640w.jpg"
srcset="
elva-fairy-320w.jpg,
elva-fairy-480w.jpg 1.5x,
elva-fairy-640w.jpg 2x
"
/>
</figure>

<p>All three images:</p>
<div class="container">
<figure>
<figcaption class="caption">elva-fairy-320w</figcaption>
<img alt="The image at 320w" src="elva-fairy-320w.jpg" />
</figure>
<figure>
<figcaption class="caption">elva-fairy-640w</figcaption>
<img alt="The image at 640w" src="elva-fairy-640w.jpg" />
</figure>
<figure>
<figcaption class="caption">elva-fairy-480w</figcaption>
<img alt="The image at 480w" src="elva-fairy-480w.jpg" />
</figure>
</div>
</body>
</html>