Created
April 3, 2018 03:19
-
-
Save lihsai0/a28fa4a12c181171319c42c79532a8f7 to your computer and use it in GitHub Desktop.
[Study] fragement in study
This file contains hidden or 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Test Fullpage</title> | |
<style> | |
html, body { | |
padding: 0; | |
margin: 0; | |
} | |
.wrap-container { | |
overflow: hidden; | |
height: 100vh; | |
width: 100vw; | |
} | |
.wrap { | |
height: 100%; | |
width: 100%; | |
} | |
.wrap > .section { | |
height: 100%; | |
width: 100%; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="wrap-container"> | |
<div class="wrap" id="scroll"> | |
<div class="section"> | |
First | |
</div> | |
<div class="section"> | |
Second | |
</div> | |
<div class="section"> | |
Third | |
</div> | |
<div class="section"> | |
Fourth | |
</div> | |
<div class="section"> | |
Fifth | |
</div> | |
</div> | |
</div> | |
</body> | |
<script> | |
let wraper = document.querySelector('#scroll'); | |
wraper.style.transform = 'translateY(0)'; | |
let sectionList = wraper.children; | |
for (section of sectionList) { | |
section.addEventListener('click', e => { | |
window.requestAnimationFrame(doScroll); | |
currentIndex++; | |
}) | |
} | |
let currentIndex = 0; | |
let start = null; | |
function doScroll (timestamp) { | |
if (!start) start = timestamp; | |
let progress = timestamp - start; | |
let transY = /\(\-?(\d+)\w*\)/.exec(wraper.style.transform); | |
transY = transY[1] * 1 + 1; | |
wraper.style.transform = 'translateY(-' + (transY) + 'vh)'; | |
if (transY < currentIndex * 100) window.requestAnimationFrame(doScroll); | |
} | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment