Skip to content

Commit 4f189bb

Browse files
committed
add 'prefers-reduced-motion' for home page
1 parent 6b8653a commit 4f189bb

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

src/components/Home.vue

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div>
33
<!-- <sp-three-vue class="canvas1" :shaderParkCode="spCode" :sculptureParams="backgroundParams" ref="canvas1" :enableZoom="false" /> -->
4-
<sp-three-vue class="background-canvas" :shaderParkCode="spCode3" :sculptureParams="backgroundParams" :enableZoom="false" />
4+
<sp-three-vue class="background-canvas" :shaderParkCode="spCode3" :sculptureParams="backgroundParams" :enableZoom="false" :pause="pause" />
55
<section class="container split-container hero">
66
<br/>
77
<a href="https://www.npmjs.com/package/shader-park-core"><h4>shader-park-core</h4></a>
@@ -110,6 +110,7 @@ import {spCode2, spCode3} from '../helpers/front-page-sculp1.js';
110110
export default {
111111
data: function() {
112112
return {
113+
pause: false,
113114
spCode: spCode2(),
114115
spCode3: spCode3(),
115116
featuredSculptures: null,
@@ -159,9 +160,14 @@ export default {
159160
} else {
160161
console.log('coudcaskdjhf no canvas')
161162
}
162-
document.addEventListener('scroll', () => {
163-
this.backgroundParams.scroll = this.backgroundParams.scroll*.98 + window.pageYOffset/window.innerHeight*.02;
164-
}, false);
163+
164+
const mediaQuery = window.matchMedia('(prefers-reduced-motion: reduce)');
165+
if (mediaQuery && mediaQuery.matches) {
166+
this.pause = true;
167+
}
168+
mediaQuery.addEventListener('change', () => {
169+
this.pause = mediaQuery.matches;
170+
});
165171
/*
166172
function resizeCanvasToDisplaySize(canvas) {
167173
// look up the size the canvas is being displayed

src/components/SpThreeVue.vue

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export default {
1818
props: {
1919
// canvasWidth: { type: String, default: '100vw' },
2020
hoverInterpolation: { type: Number, default: .98 },
21+
pause: { type: Boolean, default: false},
2122
clickInterpolation: { type: Number, default: .98 },
2223
scrollInterpolation: { type: Number, default: .98 },
2324
shaderParkCode: {type: [Function, String], default: 'sphere(.5);'},
@@ -90,6 +91,9 @@ export default {
9091
},
9192
mouseDown1() {
9293
this.state.click = 1.0;
94+
},
95+
playToggle() {
96+
this.pause = !this.pause;
9397
}
9498
},
9599
mounted() {
@@ -146,13 +150,18 @@ export default {
146150
this.$emit('beginRender');
147151
this.animationId = requestAnimationFrame( render );
148152
if('time' in this.sculptureParams) {
149-
this.sculptureParams.time += 0.01;
153+
if(!this.pause) {
154+
this.sculptureParams.time += 0.01;
155+
}
150156
} else {
151157
this.sculptureParams.time = 0;
152158
}
153-
this.sculptureParams.click = this.sculptureParams.click*this.clickInterpolation + this.state.click*(1.0-this.clickInterpolation);
154-
this.sculptureParams.hover = this.sculptureParams.hover*this.hoverInterpolation + this.state.hover*(1.0-this.hoverInterpolation);
155-
this.sculptureParams.scroll = this.sculptureParams.scroll*this.scrollInterpolation + window.pageYOffset/window.innerHeight*(1.0-this.scrollInterpolation);
159+
160+
this.sculptureParams.click = this.sculptureParams.click*this.clickInterpolation + this.state.click*(1.0-this.clickInterpolation);
161+
this.sculptureParams.hover = this.sculptureParams.hover*this.hoverInterpolation + this.state.hover*(1.0-this.hoverInterpolation);
162+
if(!this.pause) {
163+
this.sculptureParams.scroll = this.sculptureParams.scroll*this.scrollInterpolation + window.pageYOffset/window.innerHeight*(1.0-this.scrollInterpolation);
164+
}
156165
157166
// this.state.currClick = this.state.currClick*.98 + this.state.click*.02;
158167

0 commit comments

Comments
 (0)