Skip to content

Commit c540f1e

Browse files
committed
remove scroll listener on mobile
1 parent 4f189bb commit c540f1e

File tree

1 file changed

+38
-13
lines changed

1 file changed

+38
-13
lines changed

src/components/SpThreeVue.vue

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
@mouseout="state.hover = 0.0"
55
@pointerdown="state.click = 1.0"
66
@pointerup="state.click = 0.0"
7+
class="noSelect"
78
/>
89
</template>
910

@@ -30,6 +31,7 @@ export default {
3031
data () {
3132
return {
3233
favorited: false,
34+
isMobile: false,
3335
favoriteCount: 0,
3436
params: {},
3537
state: {
@@ -52,7 +54,7 @@ export default {
5254
displayActionButton() {
5355
return this.currSculpture && this.currSculpture.id && this.currSculpture.id.length > 3
5456
},
55-
isMobile() {
57+
isMobileWidth() {
5658
return window.innerWidth < 500;
5759
},
5860
currUser () {
@@ -94,13 +96,18 @@ export default {
9496
},
9597
playToggle() {
9698
this.pause = !this.pause;
97-
}
99+
},
100+
checkIsMobile() {
101+
return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
102+
},
98103
},
99104
mounted() {
100105
this.$nextTick(() => {
101106
let canvasContainer = this.$refs.canvasContainer;
102107
this.scene = new Scene();
103108
109+
this.isMobile = this.checkIsMobile();
110+
104111
this.camera = new PerspectiveCamera( 75, canvasContainer.offsetWidth/canvasContainer.offsetHeight, 0.1, 1000 );
105112
this.camera.position.z = 1.5;
106113
@@ -120,13 +127,15 @@ export default {
120127
let mesh = createSculpture(this.shaderParkCode, () => this.sculptureParams );
121128
this.scene.add(mesh);
122129
123-
this.controls = new OrbitControls( this.camera, this.renderer.domElement, {
124-
enableDamping : true,
125-
dampingFactor : 0.25,
126-
zoomSpeed : 0.5,
127-
rotateSpeed : 0.5
128-
} );
129-
this.controls.enableZoom = this.enableZoom
130+
if(!this.isMobile) {
131+
this.controls = new OrbitControls( this.camera, this.renderer.domElement, {
132+
enableDamping : true,
133+
dampingFactor : 0.25,
134+
zoomSpeed : 0.5,
135+
rotateSpeed : 0.5
136+
} );
137+
this.controls.enableZoom = this.enableZoom
138+
}
130139
131140
// let onWindowResize = () => {
132141
// this.camera.aspect = window.innerWidth / window.innerHeight;
@@ -143,6 +152,7 @@ export default {
143152
self.state.click = 1.0
144153
}, false);
145154
canvasContainer.addEventListener('mouseup', () => self.state.click = 0.0, false);
155+
canvasContainer.addEventListener('contextmenu', (e) => {e.preventDefault()}, false);
146156
147157
window.addEventListener( 'resize', this.resize );
148158
@@ -158,14 +168,17 @@ export default {
158168
}
159169
160170
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);
171+
if(!this.isMobile) {
172+
this.sculptureParams.hover = this.sculptureParams.hover*this.hoverInterpolation + this.state.hover*(1.0-this.hoverInterpolation);
173+
}
162174
if(!this.pause) {
163175
this.sculptureParams.scroll = this.sculptureParams.scroll*this.scrollInterpolation + window.pageYOffset/window.innerHeight*(1.0-this.scrollInterpolation);
164176
}
165177
166178
// this.state.currClick = this.state.currClick*.98 + this.state.click*.02;
167-
168-
this.controls.update();
179+
if(!this.isMobile) {
180+
this.controls.update();
181+
}
169182
170183
this.renderer.render( this.scene, this.camera );
171184
};
@@ -193,5 +206,17 @@ export default {
193206

194207

195208
<style lang="less" scoped>
196-
209+
.noSelect {
210+
-webkit-tap-highlight-color: transparent;
211+
-webkit-touch-callout: none;
212+
-webkit-user-select: none;
213+
-khtml-user-select: none;
214+
-moz-user-select: none;
215+
-ms-user-select: none;
216+
user-select: none;
217+
218+
}
219+
.noSelect:focus {
220+
outline: none !important;
221+
}
197222
</style>

0 commit comments

Comments
 (0)