Created
May 16, 2018 03:41
-
-
Save hideya/6ede60264b8fe85136aebe56c9a40388 to your computer and use it in GitHub Desktop.
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
document.addEventListener('DOMContentLoaded', function() { | |
if (calledWithin(60)) { | |
return; | |
} | |
var elems = document.getElementsByClassName('fadein-firsttime'); | |
for (var i = 0; i < elems.length; i++) { | |
(function() { | |
var elem = elems.item(i); | |
elem.style.transition = ''; | |
elem.style.opacity = 0; | |
window.addEventListener('load', function() { | |
var duration = elem.getAttribute('data-duration'); | |
duration = duration || '1s'; | |
elem.style.transition = 'opacity ' + duration; | |
elem.style.opacity = 1; | |
}); | |
})(); | |
} | |
function calledWithin(seconds) { | |
var now = new Date().getTime(); | |
var storage = window.sessionStorage; | |
try { | |
var last = parseInt(storage.getItem('last-called')); | |
storage.setItem('last-called', now); | |
return (now < last + seconds * 1000); | |
} | |
catch (e) { | |
return false; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment