-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharticle-transition.js
More file actions
50 lines (44 loc) · 1.75 KB
/
Copy patharticle-transition.js
File metadata and controls
50 lines (44 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
(function() {
// use the thumbnail as a background on it's parent
var postThumbnails = document.querySelectorAll('.post-thumbnail');
for ( var i in postThumbnails ) {
var children = postThumbnails[i].children;
for ( var ii in children ) {
if ( children[ii].tagName == 'IMG' ) {
//get its src
var src = children[ii].getAttribute('src');
//set .post-thumbnail's background to the img's src url
postThumbnails[i].style.backgroundImage = 'url('+src+')';
}
}
}
// set up the article transition
var featuredImage = document.getElementById('featured-image');
var currentArticle = document.getElementById('main');
var nextArticle = document.getElementById('next');
var nextArticleId = nextArticle.getAttribute('data-post-id');
featuredImage.addEventListener("click", function(){
// prevent scrolling
document.body.style.overflow = "hidden";
document.addEventListener('touchstart', function(e){
e.preventDefault();
});
//transition the articles
var translationValue = featuredImage.getBoundingClientRect().top - 50;
classie.add( currentArticle, 'fade-up-out' );
classie.remove( nextArticle, 'content-hidden' );
classie.add( nextArticle, 'easing-upward' );
nextArticle.style.webkitTransform = "translate3d(0, -"+ translationValue +"px, 0)";
nextArticle.style.mozTransform = "translate3d(0, -"+ translationValue +"px, 0)";
nextArticle.style.oTransform = "translate3d(0, -"+ translationValue +"px, 0)";
nextArticle.style.transform = "translate3d(0, -"+ translationValue +"px, 0)";
//load the next article
window.setTimeout(function(){
if (window.innerWidth <= 1024) {
location.replace( "index.php?p=" + nextArticleId );
} else {
location.assign( "index.php?p=" + nextArticleId );
}
}, 800);
});
})();