document.onmousewheel =
function
(e){
e = e || window.event
var
d = e.wheelDelta / 10 || -e.detail
radius += d
init(1)
}
var
sX,sY,nX,nY,desX = 0 , desY = 0, tX = 0,tY = 0;
document.onpointerdown =
function
(e){
e = e || window.event
var
sX = e.clientX,
sY = e.clientY
this.onpointermove =
function
(e){
console.log(e);
e = e || window.event
var
nX = e.clientX,
nY = e.clientY;
desX = nX - sX;
desY = nY - sY;
tX += desX * 0.1
tY += desY * 0.1
applyTransform(oDarg)
}
this.onpointerup =
function
(e){
oDarg.timer = setInterval(
function
(){
desX *= 0.95
desY *= 0.95
tX += desX * 0.1
tY += desY * 0.1
applyTransform(oDarg)
playSpin(false)
if
(Math.
abs
(desX) < 0.5 && Math.
abs
(desY) < 0.5){
clearInterval(oDarg.timer)
playSpin(true)
}
},17)
this.onpointermove = this.onpointerup = null
}
return
false
}
function
applyTransform(obj){
if
(tY > 180)tY = 180
if
(tY < 0)tY = 0
obj.style.transform = `rotateX(${-tY}deg) rotateY(${tX}deg)`
}
function
playSpin(yes){
oSpin.style.animationPlayState = (yes ?
'running'
:
'paused'
)
}