Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hideya/6ede60264b8fe85136aebe56c9a40388 to your computer and use it in GitHub Desktop.
Save hideya/6ede60264b8fe85136aebe56c9a40388 to your computer and use it in GitHub Desktop.
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