我的代码:
var transformString = Modernizr.prefixed('transform');
var inputDown, inputMove, inputUp;
if (window.Touch) {
inputDown = "touchstart";
inputMove = "touchmove";
inputUp = "touchend";
}
else {
inputDown = "mousedown";
inputMove = "mousemove";
inputUp = "mouseup";
}
var mouse = { startX: 0, startY: 0 };
var innerElement = $('.threedee');
function normalizedX(event){
return window.Touch ? event.originalEvent.touches[0].pageX : event.pageX;
}
function normalizedY(event){
return window.Touch ? event.originalEvent.touches[0].pageY : event.pageY;
}
$(document).bind(inputDown, function(event){
event.preventDefault();
if(event.button === 2) return true; // right-click
mouse.startX = normalizedX(event);
mouse.startY = normalizedY(event);
// store the transform state
// globalMatrix.setMatrixValue($inner.css('-webkit-transform'));
$(document)
.bind(inputMove, move)
.one(inputUp, function(){ $(document).unbind(inputMove); });
});
function move(event){
event.preventDefault();
var offsetX = normalizedX(event) - mouse.startX;
var offsetY = normalizedY(event) - mouse.startY;
if(event.shiftKey){
offsetX = roundToMultiple(offsetX, 15);
offsetY = roundToMultiple(offsetY, 15);
}
innerElement.css(transformString, 'rotateY('+offsetX+'deg) rotateX('+-offsetY+'deg)');
/* move relative to the initial position
$inner.css('-webkit-transform', globalMatrix.rotate(-offsetY, offsetX, 0));//*/
}
function roundToMultiple(number, multiple){
var value = number/multiple
, integer = Math.floor(value)
, rest = value - integer;
return rest > 0.5 ? (integer+1)*multiple : integer*multiple;
}
试着只看javascript部分,我的问题就在那里。
我想知道为什么“事件”将作为脚本中大多数函数的参数和参数传递。有时它也可能是“e”。谁创造了他们???
我自己从来没有创建过任何负责这个“事件”变量的“事件”变量。