forked from mozdevs/servo-experiments
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new demo photo-gallery
- Loading branch information
Showing
25 changed files
with
262 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.
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,169 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<link rel=stylesheet type=text/css href=photos.css></link> | ||
<style id=photo-styles></style> | ||
<meta name="viewport" content="width=device-width"> | ||
</head> | ||
<body> | ||
<footer> | ||
<div class=footer-box id=zoom-container> | ||
<div class="zoom-icon before"></div> | ||
<div id=zoom-slider data-value=240><div id=zoom-knob style="left: 80px;"></div></div> | ||
<div class="zoom-icon after"></div> | ||
</div> | ||
</footer> | ||
<main></main> | ||
<script> | ||
// xorshift | ||
function Rand() { | ||
this.x = 3141; | ||
this.y = 5926; | ||
this.z = 5358; | ||
this.w = 9793; | ||
return this; | ||
} | ||
|
||
Rand.prototype.rand = function() { | ||
var t = this.x ^ (this.x << 11); | ||
this.x = this.y; this.y = this.z; this.z = this.w; | ||
this.w = this.w ^ (this.w >> 19) ^ t ^ (t >> 8); | ||
return this.w; | ||
} | ||
|
||
var MAX_PHOTO = 20; | ||
var PHOTO_COUNT = 300; | ||
var MAX_ZOOM = 500; | ||
|
||
function zoom() { | ||
var width = +document.getElementById('zoom-slider').getAttribute('data-value'); | ||
var height = width * 3 / 4; | ||
var main = document.getElementsByTagName('main')[0]; | ||
for (var element = main.firstChild; element != null; element = element.nextSibling) { | ||
element.setAttribute('class', "photo photo-size-" + width); | ||
} | ||
} | ||
|
||
function reload() { | ||
var rng = new Rand(); | ||
var string = ""; | ||
var photoCount = PHOTO_COUNT; | ||
for (var i = 0; i < photoCount; i += 1000) { | ||
for (var j = i; j < Math.min(photoCount, j + 1000); j++) { | ||
var photoId = rng.rand() % MAX_PHOTO; | ||
var photo = "photo" + (photoId + 1) + ".jpg"; | ||
string += "<div class=photo data-photo=\"" + photo + "\" " + | ||
"style='background-image: url(" + photo + ")'></div>"; | ||
} | ||
} | ||
console.log(string); | ||
document.getElementsByTagName("main")[0].innerHTML = string; | ||
zoom(); | ||
} | ||
|
||
function onKeyDown(event) { | ||
var zoomSlider = document.getElementById('zoom-slider'); | ||
switch (event.keyCode) { | ||
case 83: | ||
// 's' | ||
zoomSlider.setAttribute('data-value', +zoomSlider.getAttribute('data-value') + 40); | ||
zoom(); | ||
break; | ||
case 65: | ||
// 'a' | ||
zoomSlider.setAttribute('data-value', +zoomSlider.getAttribute('data-value') - 40); | ||
zoom(); | ||
break; | ||
} | ||
} | ||
|
||
function initPhotoStyles() { | ||
var css = ""; | ||
for (var i = 0; i <= MAX_ZOOM; i++) { | ||
var height = i * 3 / 4; | ||
css += ".photo-size-" + i + " { width: " + i + "px; height: " + height + | ||
"px; }"; | ||
} | ||
document.getElementById('photo-styles').innerHTML = css; | ||
} | ||
|
||
var sliding = null; | ||
function startSliding(event) { | ||
console.log("mousedown"); | ||
sliding = event.screenX; | ||
} | ||
|
||
function stopSliding(event) { | ||
sliding = null; | ||
} | ||
|
||
function slide(event) { | ||
var zoomSlider = document.getElementById('zoom-slider'); | ||
var clientX = event.clientX; | ||
var element = zoomSlider; | ||
var width = zoomSlider.clientWidth; | ||
while (element != null) { | ||
if (element.offsetLeft) | ||
clientX -= element.offsetLeft; | ||
element = element.parentNode; | ||
} | ||
console.log("mousemove " + clientX); | ||
var newValue = (clientX / width * MAX_ZOOM) | 0; | ||
document.getElementById('zoom-knob').setAttribute('style', "left: " + clientX + "px"); | ||
zoomSlider.setAttribute('data-value', newValue); | ||
zoom(); | ||
} | ||
|
||
var zoomSlider = document.getElementById('zoom-slider'); | ||
/*zoomKnob.addEventListener('mousedown', startSliding, false); | ||
zoomKnob.addEventListener('mouseup', stopSliding, false); | ||
zoomSlider.addEventListener('click', startSliding, false);*/ | ||
zoomSlider.addEventListener('mousemove', slide, false); | ||
|
||
zoomSlider.addEventListener('touchstart', function(ev) { | ||
startSliding(ev.changedTouches[0]); | ||
ev.preventDefault(); | ||
}, false); | ||
|
||
zoomSlider.addEventListener('touchmove', function(ev) { | ||
slide(ev.changedTouches[0]); | ||
}, false); | ||
|
||
zoomSlider.addEventListener('touchend', function(ev) { | ||
stopSliding(ev.changedTouches[0]); | ||
ev.preventDefault(); | ||
}, false); | ||
|
||
|
||
/* | ||
var lastFrameTime = Date.now(); | ||
function makeALittleBigger() { | ||
var zoomSlider = document.getElementById('zoom-slider'); | ||
if (+zoomSlider.value >= 500) | ||
return; | ||
var thisFrameTime = Date.now(); | ||
var valueIncrement = ((thisFrameTime - lastFrameTime) / 100) | 0; | ||
if (valueIncrement > 0) { | ||
var valueIncrement = 1; | ||
zoomSlider.value = +zoomSlider.value + valueIncrement; | ||
zoom(); | ||
//lastFrameTime = thisFrameTime; | ||
console.log(zoomSlider.value); | ||
//} | ||
setTimeout(makeALittleBigger, 16); | ||
} | ||
*/ | ||
|
||
document.addEventListener('keydown', onKeyDown, true); | ||
|
||
document.getElementById('zoom-slider').setAttribute('data-value', 240); | ||
|
||
initPhotoStyles(); | ||
reload(); | ||
|
||
//setTimeout(makeALittleBigger, 16); | ||
|
||
</script> | ||
</body> | ||
</html> | ||
|
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.
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,87 @@ | ||
body { | ||
background: #676767; | ||
overflow: hidden; | ||
font: 12px Helvetica; | ||
} | ||
main { | ||
/* position: fixed; /* comment this out to make it work in Servo :( */ | ||
overflow: scroll; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 25px; | ||
text-align: center; | ||
} | ||
footer { | ||
position: fixed; | ||
bottom: 0; | ||
left: 0; | ||
right: 0; | ||
height: 40px; | ||
border-top: solid 1px #515151; | ||
/*background: linear-gradient(top, #ececec, #d2d2d2); | ||
background: -moz-linear-gradient(top, #ececec, #d2d2d2); | ||
background: -webkit-linear-gradient(top, #ececec, #d2d2d2);*/ | ||
background: #ececec; | ||
color: #6b6b6b; | ||
z-index: 1; | ||
} | ||
.footer-box { | ||
position: absolute; | ||
left: 0; | ||
right: 0; | ||
top: 0; | ||
bottom: 0; | ||
} | ||
#zoom-container { | ||
padding: 1px 23px; | ||
right: 16px; | ||
} | ||
#count-container { | ||
left: 3px; | ||
padding-top: 2px; | ||
} | ||
.zoom-icon { | ||
content: "Hello"; | ||
position: absolute; | ||
display: block; | ||
background: url(glyphicons-4-user.png) center center no-repeat; | ||
top: 8px; | ||
width: 23px; | ||
height: 22px; | ||
opacity: 0.5; | ||
} | ||
.zoom-icon.before { | ||
background-size: 8px 8px; | ||
left: 0; | ||
} | ||
.zoom-icon.after { | ||
background-size: 14px 14px; | ||
right: 0; | ||
} | ||
.photo { | ||
background: url(mimi.jpg) center center / contain no-repeat; | ||
display: inline-block; | ||
margin: 6px; | ||
/*filter: drop-shadow(0 3px 3px #444); | ||
-webkit-filter: drop-shadow(0 3px 3px #444);*/ | ||
} | ||
#zoom-slider { | ||
position: absolute; | ||
top: 12px; | ||
height: 16px; | ||
left: 32px; | ||
right: 32px; | ||
border-radius: 8px; | ||
border: solid 1px black; | ||
} | ||
#zoom-knob { | ||
position: absolute; | ||
top: -8px; | ||
bottom: 0; | ||
width: 32px; | ||
height: 32px; | ||
border-radius: 32px; | ||
background: black; | ||
} | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.