Skip to content
This repository was archived by the owner on May 21, 2018. It is now read-only.

Commit dca9ab4

Browse files
committed
Smoothen parallax effect for desktop and disable on mobile
Having CSS transitions applied to masthead transformations was resulting in very choppy behaviour when scrolling; the effect subsided by removing the transitions (it's smoother without them). Furthermore, it's hopeless to make this effect look good on mobile devices, since they throttle the onScroll event too much for it to look good.
1 parent b6dc9cf commit dca9ab4

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

src/css/page.home.css

+12-6
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,29 @@ body{
7878
left: 0;
7979
right: 0;
8080
bottom: 0;
81-
transform-origin: 50% 100%;
8281
}
8382
/** Individual hero image */
8483
#hero > div{
8584
background-position: 50% 50%;
8685
background-size: cover;
87-
transition: 0s ease opacity 2s, .1s ease transform-origin;
88-
transform: scale( 1.5);
89-
transform: scale3d(1.5, 1.5, 1.5);
90-
transform-origin: inherit;
86+
transition: 0s ease opacity 2s;
9187
z-index: -2;
9288
opacity: 0;
9389
}
9490
#hero > .active{
9591
opacity: 1;
9692
z-index: -1;
97-
transition: 2s ease opacity, .1s ease transform-origin;
93+
transition: 2s ease opacity;
94+
}
95+
96+
/** Parallax-enabled masthead (non-touchscreen only) */
97+
.parallax #hero{
98+
transform-origin: 50% 100%;
99+
}
100+
.parallax #hero > div{
101+
transform: scale(1.5);
102+
transform: scale3d(1.5, 1.5, 1.5);
103+
transform-origin: inherit;
98104
}
99105

100106

src/js/page.home.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
var BY_ID = "getElementById",
55
QUERY = "querySelector",
66
QUERY_ALL = QUERY + "All",
7+
HTML = DOC.documentElement,
8+
htmlClass = HTML.classList,
79
UNDEF;
810

911

@@ -96,12 +98,16 @@
9698
new Rotator(hero, {autoplay: 5000});
9799

98100

99-
/** Parallax, etc */
100-
window.addEventListener("scroll", function(e){
101-
hero.style.transformOrigin = "50% "+(
102-
(1 - Math.min(window.pageYOffset / hero.getBoundingClientRect().height, 1)) * 100
103-
)+"%";
104-
});
101+
/** Add scrolling parallax effect for NON-touchscreen devices */
102+
if(!("ontouchstart" in window)){
103+
htmlClass.add("parallax");
104+
105+
window.addEventListener("scroll", function(e){
106+
hero.style.transformOrigin = "50% "+(
107+
(1 - Math.min(window.pageYOffset / hero.getBoundingClientRect().height, 1)) * 100
108+
)+"%";
109+
});
110+
}
105111

106112

107113

@@ -163,7 +169,7 @@
163169
*/
164170
DOC[ QUERY ]("#topnav > .i").addEventListener("click", function(e){
165171

166-
if(!DOC.documentElement.classList.contains("pin-nav")){
172+
if(!htmlClass.contains("pin-nav")){
167173
scrollToNav(true);
168174
e.preventDefault();
169175
return false;

0 commit comments

Comments
 (0)