forked from mdn/css-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.
Merge https://github.com/mdn/object-fit-gallery into this repo. Origi…
…nal code by @chrisdavidmills
- Loading branch information
Showing
20 changed files
with
123 additions
and
0 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,44 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | ||
<meta name="viewport" content="width=device-width"> | ||
|
||
<title>Object-fit gallery</title> | ||
|
||
<link rel="stylesheet" href="style.css"> | ||
<!--[if lt IE 9]> | ||
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> | ||
<![endif]--> | ||
</head> | ||
|
||
<body> | ||
<div class="top-row"> | ||
<img class="thumb"> | ||
<img class="thumb"> | ||
<img class="thumb"> | ||
<img class="thumb"> | ||
</div> | ||
<div class="second-row"> | ||
<img class="thumb"> | ||
<img class="thumb"> | ||
<img class="thumb"> | ||
<img class="thumb"> | ||
</div> | ||
<div class="third-row"> | ||
<img class="thumb"> | ||
<img class="thumb"> | ||
<img class="thumb"> | ||
<img class="thumb"> | ||
</div> | ||
<div class="bottom-row"> | ||
<img class="thumb"> | ||
<img class="thumb"> | ||
<img class="thumb"> | ||
<img class="thumb"> | ||
</div> | ||
<img class="main"> | ||
</body> | ||
<script src="main.js"></script> | ||
</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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
var thumbs = document.querySelectorAll('.thumb'); | ||
var mainImg = document.querySelector('.main'); | ||
|
||
for(i = 1; i <= thumbs.length ; i++) { | ||
var requestObj = 'images/pic' + i + '.jpg'; | ||
retrieveImage(requestObj,i-1); | ||
} | ||
|
||
function retrieveImage(requestObj,imageNo) { | ||
var request = new XMLHttpRequest(); | ||
request.open('GET', requestObj, true); | ||
request.responseType = 'blob'; | ||
request.send(); | ||
|
||
request.onload = function() { | ||
var objectURL = URL.createObjectURL(request.response); | ||
thumbs[imageNo].setAttribute('src',objectURL); | ||
thumbs[imageNo].onclick = function() { | ||
mainImg.setAttribute('src',objectURL); | ||
mainImg.className = 'blowup'; | ||
for(i = 0; i < thumbs.length; i++) { | ||
thumbs[i].className = 'thumb darken'; | ||
} | ||
} | ||
} | ||
} | ||
|
||
mainImg.onclick = function() { | ||
mainImg.className = 'main'; | ||
for(i = 0; i < thumbs.length; i++) { | ||
thumbs[i].className = 'thumb'; | ||
} | ||
} |
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,44 @@ | ||
html { | ||
margin: 0; | ||
background: black; | ||
height: 100%; | ||
} | ||
|
||
body { | ||
margin: 0; | ||
width: 100%; | ||
height: inherit; | ||
} | ||
|
||
/* the three main rows going down the page */ | ||
|
||
body > div { | ||
height: 25%; | ||
} | ||
|
||
.thumb { | ||
float: left; | ||
width: 25%; | ||
height: 100%; | ||
object-fit: cover; | ||
} | ||
|
||
.main { | ||
display: none; | ||
} | ||
|
||
.blowup { | ||
display: block; | ||
position: absolute; | ||
object-fit: contain; | ||
object-position: center; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
z-index: 2000; | ||
} | ||
|
||
.darken { | ||
opacity: 0.4; | ||
} |