mirror of
https://github.com/meineerde/holgerjust.de.git
synced 2025-10-17 17:01:01 +00:00
Get rid of jQuery \o/
This commit is contained in:
parent
cf984e1a07
commit
8e33919016
@ -17,7 +17,7 @@ cover_license: '[Cover Image](https://unsplash.com/photos/2ShvY8Lf6l0) by [Lukas
|
||||
%span= "by #{link_to blog_author.name, author_path}"
|
||||
= partial(:profile_links, locals: {author: blog_author.name})
|
||||
|
||||
%a.scroll-down.icon-arrow-left{href: '#content', data: {offset: '-45'}}
|
||||
%a.scroll-down.icon-arrow-left{href: '#content', data: {offset: '45'}}
|
||||
%span.hidden Scroll Down
|
||||
|
||||
%main#content.content{role: :main}
|
||||
|
||||
2
source/javascripts/application.js
Normal file
2
source/javascripts/application.js
Normal file
@ -0,0 +1,2 @@
|
||||
#= require casper
|
||||
#= require obfuscate
|
||||
@ -1,3 +0,0 @@
|
||||
#= require vendor/jquery-1.12.0
|
||||
#= require vendor/casper
|
||||
#= require obfuscate
|
||||
101
source/javascripts/casper.js
Normal file
101
source/javascripts/casper.js
Normal file
@ -0,0 +1,101 @@
|
||||
(function() {
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
document.querySelectorAll('.menu-button, .nav-cover, .nav-close').forEach(function(element) {
|
||||
element.addEventListener('click', function(event) {
|
||||
event.preventDefault();
|
||||
|
||||
var body_classes = document.body.className.split(' ');
|
||||
["nav-opened", "nav-closed"].forEach(function(klass){
|
||||
var i = body_classes.indexOf(klass);
|
||||
i >= 0 ? body_classes.splice(i, 1) : body_classes.push(klass);
|
||||
});
|
||||
document.body.className = body_classes.join(' ');
|
||||
});
|
||||
});
|
||||
}, false);
|
||||
|
||||
// slightly adapted from http://stackoverflow.com/a/26798337/421705
|
||||
window.requestAnimFrame = (function(){
|
||||
return window.requestAnimationFrame ||
|
||||
window.webkitRequestAnimationFrame ||
|
||||
window.mozRequestAnimationFrame ||
|
||||
function( callback ){
|
||||
window.setTimeout(callback, 1000 / 60);
|
||||
};
|
||||
})();
|
||||
|
||||
function scrollToY(scrollTargetY, speed, easing) {
|
||||
// scrollTargetY: the target scrollY property of the window
|
||||
// speed: time in pixels per second
|
||||
// easing: easing equation to use
|
||||
|
||||
var scrollY = window.scrollY,
|
||||
scrollTargetY = scrollTargetY || 0,
|
||||
speed = speed || 2000,
|
||||
easing = easing || 'easeOutSine',
|
||||
currentTime = 0;
|
||||
|
||||
// min time .1, max time .8 seconds
|
||||
var time = Math.max(.1, Math.min(Math.abs(scrollY - scrollTargetY) / speed, .8));
|
||||
|
||||
// easing equations from https://github.com/danro/easing-js/blob/master/easing.js
|
||||
var PI_D2 = Math.PI / 2,
|
||||
easingEquations = {
|
||||
easeOutSine: function (pos) {
|
||||
return Math.sin(pos * (Math.PI / 2));
|
||||
},
|
||||
easeInOutSine: function (pos) {
|
||||
return (-0.5 * (Math.cos(Math.PI * pos) - 1));
|
||||
},
|
||||
easeInOutQuint: function (pos) {
|
||||
if ((pos /= 0.5) < 1) {
|
||||
return 0.5 * Math.pow(pos, 5);
|
||||
}
|
||||
return 0.5 * (Math.pow((pos - 2), 5) + 2);
|
||||
}
|
||||
};
|
||||
|
||||
// add animation loop
|
||||
function tick() {
|
||||
currentTime += 1 / 60;
|
||||
|
||||
var p = currentTime / time;
|
||||
var t = easingEquations[easing](p);
|
||||
|
||||
if (p < 1) {
|
||||
requestAnimFrame(tick);
|
||||
window.scrollTo(0, scrollY + ((scrollTargetY - scrollY) * t));
|
||||
} else {
|
||||
window.scrollTo(0, scrollTargetY);
|
||||
}
|
||||
}
|
||||
|
||||
// call it once to get started
|
||||
tick();
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
document.querySelectorAll('.scroll-down').forEach(function(element) {
|
||||
element.addEventListener('click', function(event) {
|
||||
event.preventDefault();
|
||||
|
||||
var speed = 500,
|
||||
offset = this.getAttribute('data-offset') ? this.getAttribute('data-offset') : false,
|
||||
position = this.getAttribute('data-position') ? this.getAttribute('data-position') : false,
|
||||
toMove;
|
||||
|
||||
var elementBottom = this.getBoundingClientRect().bottom + window.pageYOffset - (document.clientTop || 0);
|
||||
|
||||
if (offset) {
|
||||
toMove = parseInt(offset);
|
||||
scrollToY(elementBottom + toMove, speed, 'easeInOutQuint')
|
||||
} else if (position) {
|
||||
toMove = parseInt(position);
|
||||
scrollToY(toMove, speed, 'easeInOutQuint')
|
||||
} else {
|
||||
scrollToY(elementBottom, speed, 'easeInOutQuint')
|
||||
}
|
||||
});
|
||||
});
|
||||
}, false);
|
||||
})();
|
||||
@ -30,4 +30,4 @@
|
||||
element.innerHTML = link;
|
||||
});
|
||||
}, false);
|
||||
})()
|
||||
})();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user