event.wheeldelta=event is undefinedd是怎么发生的?

JavaScript
* @author qiao / https://github.com/qiao
* @author mrdoob / http://mrdoob.com
* @author alteredq / http://alteredqualia.com/
* @author WestLangley / http://github.com/WestLangley
* @author erich666 / http://erichaines.com
/*global THREE, console */
// This set of controls performs orbiting, dollying (zooming), and panning. It maintains
// the "up" direction as +Y, unlike the TrackballControls. Touch on tablet and phones is
// supported.
Orbit - left mouse / touch: one finger move
Zoom - middle mouse, or mousewheel / touch: two finger spread or squish
Pan - right mouse, or arrow keys / touch: three finter swipe
THREE.OrbitControls = function ( object, domElement ) {
this.object =
this.domElement = ( domElement !== undefined ) ? domElement :
// Set to false to disable this control
this.enabled =
// "target" sets the location of focus, where the control orbits around
// and where it pans with respect to.
this.target = new THREE.Vector3();
// center is old, use "target" instead
this.center = this.
// This option actually enables left as "zoom" for
// backwards compatibility
this.noZoom =
this.zoomSpeed = 1.0;
// Limits to how far you can dolly in and out ( PerspectiveCamera only )
this.minDistance = 0;
this.maxDistance = I
// Limits to how far you can zoom in and out ( OrthographicCamera only )
this.minZoom = 0;
this.maxZoom = I
// Set to true to disable this control
this.noRotate =
this.rotateSpeed = 1.0;
// Set to true to disable this control
this.noPan =
this.keyPanSpeed = 7.0; // pixels moved per arrow key push
// Set to true to automatically rotate around the target
this.autoRotate =
this.autoRotateSpeed = 2.0; // 30 seconds per round when fps is 60
// How far you can orbit vertically, upper and lower limits.
// Range is 0 to Math.PI radians.
this.minPolarAngle = 0; // radians
this.maxPolarAngle = Math.PI; // radians
// How far you can orbit horizontally, upper and lower limits.
// If set, must be a sub-interval of the interval [ - Math.PI, Math.PI ].
this.minAzimuthAngle = - I // radians
this.maxAzimuthAngle = I // radians
// Set to true to disable use of the keys
this.noKeys =
// The four arrow keys
this.keys = { LEFT: 37, UP: 38, RIGHT: 39, BOTTOM: 40 };
// Mouse buttons
this.mouseButtons = { ORBIT: THREE.MOUSE.LEFT, ZOOM: THREE.MOUSE.MIDDLE, PAN: THREE.MOUSE.RIGHT };
////////////
// internals
var scope =
var EPS = 0.000001;
var rotateStart = new THREE.Vector2();
var rotateEnd = new THREE.Vector2();
var rotateDelta = new THREE.Vector2();
var panStart = new THREE.Vector2();
var panEnd = new THREE.Vector2();
var panDelta = new THREE.Vector2();
var panOffset = new THREE.Vector3();
var offset = new THREE.Vector3();
var dollyStart = new THREE.Vector2();
var dollyEnd = new THREE.Vector2();
var dollyDelta = new THREE.Vector2();
var phiDelta = 0;
var thetaDelta = 0;
var scale = 1;
var pan = new THREE.Vector3();
var lastPosition = new THREE.Vector3();
var lastQuaternion = new THREE.Quaternion();
var STATE = { NONE : -1, ROTATE : 0, DOLLY : 1, PAN : 2, TOUCH_ROTATE : 3, TOUCH_DOLLY : 4, TOUCH_PAN : 5 };
var state = STATE.NONE;
// for reset
this.target0 = this.target.clone();
this.position0 = this.object.position.clone();
this.zoom0 = this.object.
// so camera.up is the orbit axis
var quat = new THREE.Quaternion().setFromUnitVectors( object.up, new THREE.Vector3( 0, 1, 0 ) );
var quatInverse = quat.clone().inverse();
var changeEvent = { type: 'change' };
var startEvent = { type: 'start' };
var endEvent = { type: 'end' };
this.rotateLeft = function ( angle ) {
if ( angle === undefined ) {
angle = getAutoRotationAngle();
thetaDelta -=
this.rotateUp = function ( angle ) {
if ( angle === undefined ) {
angle = getAutoRotationAngle();
phiDelta -=
// pass in distance in world space to move left
this.panLeft = function ( distance ) {
var te = this.object.matrix.
// get X column of matrix
panOffset.set( te[ 0 ], te[ 1 ], te[ 2 ] );
panOffset.multiplyScalar( - distance );
pan.add( panOffset );
// pass in distance in world space to move up
this.panUp = function ( distance ) {
var te = this.object.matrix.
// get Y column of matrix
panOffset.set( te[ 4 ], te[ 5 ], te[ 6 ] );
panOffset.multiplyScalar( distance );
pan.add( panOffset );
// pass in x,y of change desired in pixel space,
// right and down are positive
this.pan = function ( deltaX, deltaY ) {
var element = scope.domElement === document ? scope.domElement.body : scope.domE
if ( scope.object instanceof THREE.PerspectiveCamera ) {
// perspective
var position = scope.object.
var offset = position.clone().sub( scope.target );
var targetDistance = offset.length();
// half of the fov is center to top of screen
targetDistance *= Math.tan( ( scope.object.fov / 2 ) * Math.PI / 180.0 );
// we actually don't use screenWidth, since perspective camera is fixed to screen height
scope.panLeft( 2 * deltaX * targetDistance / element.clientHeight );
scope.panUp( 2 * deltaY * targetDistance / element.clientHeight );
} else if ( scope.object instanceof THREE.OrthographicCamera ) {
// orthographic
scope.panLeft( deltaX * (scope.object.right - scope.object.left) / element.clientWidth );
scope.panUp( deltaY * (scope.object.top - scope.object.bottom) / element.clientHeight );
// camera neither orthographic or perspective
console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.' );
this.dollyIn = function ( dollyScale ) {
if ( dollyScale === undefined ) {
dollyScale = getZoomScale();
if ( scope.object instanceof THREE.PerspectiveCamera ) {
scale /= dollyS
} else if ( scope.object instanceof THREE.OrthographicCamera ) {
scope.object.zoom = Math.max( this.minZoom, Math.min( this.maxZoom, this.object.zoom * dollyScale ) );
scope.object.updateProjectionMatrix();
scope.dispatchEvent( changeEvent );
console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
this.dollyOut = function ( dollyScale ) {
if ( dollyScale === undefined ) {
dollyScale = getZoomScale();
if ( scope.object instanceof THREE.PerspectiveCamera ) {
scale *= dollyS
} else if ( scope.object instanceof THREE.OrthographicCamera ) {
scope.object.zoom = Math.max( this.minZoom, Math.min( this.maxZoom, this.object.zoom / dollyScale ) );
scope.object.updateProjectionMatrix();
scope.dispatchEvent( changeEvent );
console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
this.update = function () {
var position = this.object.
offset.copy( position ).sub( this.target );
// rotate offset to "y-axis-is-up" space
offset.applyQuaternion( quat );
// angle from z-axis around y-axis
theta = Math.atan2( offset.x, offset.z );
// angle from y-axis
phi = Math.atan2( Math.sqrt( offset.x * offset.x + offset.z * offset.z ), offset.y );
if ( this.autoRotate && state === STATE.NONE ) {
this.rotateLeft( getAutoRotationAngle() );
theta += thetaD
phi += phiD
// restrict theta to be between desired limits
theta = Math.max( this.minAzimuthAngle, Math.min( this.maxAzimuthAngle, theta ) );
// restrict phi to be between desired limits
phi = Math.max( this.minPolarAngle, Math.min( this.maxPolarAngle, phi ) );
// restrict phi to be betwee EPS and PI-EPS
phi = Math.max( EPS, Math.min( Math.PI - EPS, phi ) );
var radius = offset.length() *
// restrict radius to be between desired limits
radius = Math.max( this.minDistance, Math.min( this.maxDistance, radius ) );
// move target to panned location
this.target.add( pan );
offset.x = radius * Math.sin( phi ) * Math.sin( theta );
offset.y = radius * Math.cos( phi );
offset.z = radius * Math.sin( phi ) * Math.cos( theta );
// rotate offset back to "camera-up-vector-is-up" space
offset.applyQuaternion( quatInverse );
position.copy( this.target ).add( offset );
this.object.lookAt( this.target );
thetaDelta = 0;
phiDelta = 0;
scale = 1;
pan.set( 0, 0, 0 );
// update condition is:
// min(camera displacement, camera rotation in radians)^2 > EPS
// using small-angle approximation cos(x/2) = 1 - x^2 / 8
if ( lastPosition.distanceToSquared( this.object.position ) > EPS
|| 8 * (1 - lastQuaternion.dot(this.object.quaternion)) > EPS ) {
this.dispatchEvent( changeEvent );
lastPosition.copy( this.object.position );
lastQuaternion.copy (this.object.quaternion );
this.reset = function () {
state = STATE.NONE;
this.target.copy( this.target0 );
this.object.position.copy( this.position0 );
this.object.zoom = this.zoom0;
this.object.updateProjectionMatrix();
this.dispatchEvent( changeEvent );
this.update();
this.getPolarAngle = function () {
this.getAzimuthalAngle = function () {
return theta
function getAutoRotationAngle() {
return 2 * Math.PI / 60 / 60 * scope.autoRotateS
function getZoomScale() {
return Math.pow( 0.95, scope.zoomSpeed );
function onMouseDown( event ) {
if ( scope.enabled === false )
event.preventDefault();
if ( event.button === scope.mouseButtons.ORBIT ) {
if ( scope.noRotate === true )
state = STATE.ROTATE;
rotateStart.set( event.clientX, event.clientY );
} else if ( event.button === scope.mouseButtons.ZOOM ) {
if ( scope.noZoom === true )
state = STATE.DOLLY;
dollyStart.set( event.clientX, event.clientY );
} else if ( event.button === scope.mouseButtons.PAN ) {
if ( scope.noPan === true )
state = STATE.PAN;
panStart.set( event.clientX, event.clientY );
if ( state !== STATE.NONE ) {
document.addEventListener( 'mousemove', onMouseMove, false );
document.addEventListener( 'mouseup', onMouseUp, false );
scope.dispatchEvent( startEvent );
function onMouseMove( event ) {
if ( scope.enabled === false )
event.preventDefault();
var element = scope.domElement === document ? scope.domElement.body : scope.domE
if ( state === STATE.ROTATE ) {
if ( scope.noRotate === true )
rotateEnd.set( event.clientX, event.clientY );
rotateDelta.subVectors( rotateEnd, rotateStart );
// rotating across whole screen goes 360 degrees around
scope.rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth * scope.rotateSpeed );
// rotating up and down along whole screen attempts to go 360, but limited to 180
scope.rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight * scope.rotateSpeed );
rotateStart.copy( rotateEnd );
} else if ( state === STATE.DOLLY ) {
if ( scope.noZoom === true )
dollyEnd.set( event.clientX, event.clientY );
dollyDelta.subVectors( dollyEnd, dollyStart );
if ( dollyDelta.y > 0 ) {
scope.dollyIn();
} else if ( dollyDelta.y
scope.dollyOut();
} else if ( delta
scope.dollyOut();
} else if ( dollyDelta.y
0 && seed < 1) {
// Scale the seed out
seed *= 65536;
seed = Math.floor(seed);
if(seed < 256) {
seed |= seed << 8;
for(var i = 0; i >8) & 255);
perm[i] = perm[i + 256] =
gradP[i] = gradP[i + 256] = grad3[v % 12];
module.seed(0);
for(var i=0; iy0) { // lower triangle, XY order: (0,0)->(1,0)->(1,1)
i1=1; j1=0;
// upper triangle, YX order: (0,0)->(0,1)->(1,1)
i1=0; j1=1;
// A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and
// a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where
// c = (3-sqrt(3))/6
var x1 = x0 - i1 + G2; // Offsets for middle corner in (x,y) unskewed coords
var y1 = y0 - j1 + G2;
var x2 = x0 - 1 + 2 * G2; // Offsets for last corner in (x,y) unskewed coords
var y2 = y0 - 1 + 2 * G2;
// Work out the hashed gradient indices of the three simplex corners
var gi0 = gradP[i+perm[j]];
var gi1 = gradP[i+i1+perm[j+j1]];
var gi2 = gradP[i+1+perm[j+1]];
// Calculate the contribution from the three corners
var t0 = 0.5 - x0*x0-y0*y0;
if(t0<0) {
n0 = t0 * t0 * gi0.dot2(x0, y0);
// (x,y) of grad3 used for 2D gradient
var t1 = 0.5 - x1*x1-y1*y1;
if(t1<0) {
n1 = t1 * t1 * gi1.dot2(x1, y1);
var t2 = 0.5 - x2*x2-y2*y2;
if(t2= y0) {
if(y0 >= z0)
{ i1=1; j1=0; k1=0; i2=1; j2=1; k2=0; }
else if(x0 >= z0) { i1=1; j1=0; k1=0; i2=1; j2=0; k2=1; }
{ i1=0; j1=0; k1=1; i2=1; j2=0; k2=1; }
if(y0 < z0)
{ i1=0; j1=0; k1=1; i2=0; j2=1; k2=1; }
else if(x0 < z0) { i1=0; j1=1; k1=0; i2=0; j2=1; k2=1; }
{ i1=0; j1=1; k1=0; i2=1; j2=1; k2=0; }
// A step of (1,0,0) in (i,j,k) means a step of (1-c,-c,-c) in (x,y,z),
// a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and
// a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where
// c = 1/6.
var x1 = x0 - i1 + G3; // Offsets for second corner
var y1 = y0 - j1 + G3;
var z1 = z0 - k1 + G3;
var x2 = x0 - i2 + 2 * G3; // Offsets for third corner
var y2 = y0 - j2 + 2 * G3;
var z2 = z0 - k2 + 2 * G3;
var x3 = x0 - 1 + 3 * G3; // Offsets for fourth corner
var y3 = y0 - 1 + 3 * G3;
var z3 = z0 - 1 + 3 * G3;
// Work out the hashed gradient indices of the four simplex corners
var gi0 = gradP[i+
var gi1 = gradP[i+i1+perm[j+j1+perm[k+k1]]];
var gi2 = gradP[i+i2+perm[j+j2+perm[k+k2]]];
var gi3 = gradP[i+ 1+perm[j+ 1+perm[k+ 1]]];
// Calculate the contribution from the four corners
var t0 = 0.6 - x0*x0 - y0*y0 - z0*z0;
if(t0<0) {
n0 = t0 * t0 * gi0.dot3(x0, y0, z0);
// (x,y) of grad3 used for 2D gradient
var t1 = 0.6 - x1*x1 - y1*y1 - z1*z1;
if(t1<0) {
n1 = t1 * t1 * gi1.dot3(x1, y1, z1);
var t2 = 0.6 - x2*x2 - y2*y2 - z2*z2;
if(t2<0) {
n2 = t2 * t2 * gi2.dot3(x2, y2, z2);
var t3 = 0.6 - x3*x3 - y3*y3 - z3*z3;
if(t3<0) {
n3 = t3 * t3 * gi3.dot3(x3, y3, z3);
// Add contributions from each corner to get the final noise value.
// The result is scaled to return values in the interval [-1,1].
return 32 * (n0 + n1 + n2 + n3);
// ##### Perlin noise stuff
function fade(t) {
return t*t*t*(t*(t*6-15)+10);
function lerp(a, b, t) {
return (1-t)*a + t*b;
// 2D Perlin Noise
module.perlin2 = function(x, y) {
// Find unit grid cell containing point
var X = Math.floor(x), Y = Math.floor(y);
// Get relative xy coordinates of point within that cell
x = x - X; y = y - Y;
// Wrap the integer cells at 255 (smaller integer period can be introduced here)
X = X & 255; Y = Y & 255;
// Calculate noise contributions from each of the four corners
var n00 = gradP[X+perm[Y]].dot2(x, y);
var n01 = gradP[X+perm[Y+1]].dot2(x, y-1);
var n10 = gradP[X+1+perm[Y]].dot2(x-1, y);
var n11 = gradP[X+1+perm[Y+1]].dot2(x-1, y-1);
// Compute the fade curve value for x
var u = fade(x);
// Interpolate the four results
return lerp(
lerp(n00, n10, u),
lerp(n01, n11, u),
// 3D Perlin Noise
module.perlin3 = function(x, y, z) {
// Find unit grid cell containing point
var X = Math.floor(x), Y = Math.floor(y), Z = Math.floor(z);
// Get relative xyz coordinates of point within that cell
x = x - X; y = y - Y; z = z - Z;
// Wrap the integer cells at 255 (smaller integer period can be introduced here)
X = X & 255; Y = Y & 255; Z = Z & 255;
// Calculate noise contributions from each of the eight corners
var n000 = gradP[X+
]]].dot3(x,
var n001 = gradP[X+
perm[Z+1]]].dot3(x,
var n010 = gradP[X+
perm[Y+1+perm[Z
]]].dot3(x,
var n011 = gradP[X+
perm[Y+1+perm[Z+1]]].dot3(x,
y-1, z-1);
var n100 = gradP[X+1+perm[Y+
]]].dot3(x-1,
var n101 = gradP[X+1+perm[Y+
perm[Z+1]]].dot3(x-1,
var n110 = gradP[X+1+perm[Y+1+perm[Z
]]].dot3(x-1, y-1,
var n111 = gradP[X+1+perm[Y+1+perm[Z+1]]].dot3(x-1, y-1, z-1);
// Compute the fade curve value for x, y, z
var u = fade(x);
var v = fade(y);
var w = fade(z);
// Interpolate
return lerp(
lerp(n000, n100, u),
lerp(n001, n101, u), w),
lerp(n010, n110, u),
lerp(n011, n111, u), w),
var ww, wh, renderer, scene, camera, planet,
function init() {
ww = window.innerW
wh = window.innerH
renderer = new THREE.WebGLRenderer({
canvas: document.getElementById("scene"),
antialias: true
renderer.setSize(ww, wh);
renderer.setClearColor(0xe6daf9);
renderer.setPixelRatio(window.devicePixelRatio ? window.devicePixelRatio : 1);
scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xe6daf9, 310, 550);
camera = new THREE.PerspectiveCamera(50, ww / wh, 20, 10000);
camera.position.set(0, 0, 600);
scene.add(camera);
createPlanet();
requestAnimationFrame(render);
window.addEventListener("resize", onWindowResize);
function onWindowResize() {
ww = window.innerW
wh = window.innerH
camera.aspect = ww /
camera.updateProjectionMatrix();
renderer.setSize(ww, wh);
function createPlanet() {
planet = new THREE.Object3D();
scene.add(planet);
var geometry = new THREE.Geometry();
for (var x = 0; x = 0; i--) {
var vector = geometry.vertices[i];
for (var j = geometry.vertices.length - 1; j >= 0; j--) {
if (vector.distanceTo(geometry.vertices[j]) < 25 && vector.amount < 6) {
segments.vertices.push(vector);
segments.vertices.push(geometry.vertices[j]);
geometry.vertices[i].amount++;
geometry.vertices[j].amount++;
perlin = Math.abs(noise.simplex3(vector.x * 0.005, vector.y * 0.005, vector.z * 0.002));
color = new THREE.Color("hsl(" + (perlin * 80 + 220) + ", 50%,50%)")
segments.colors.push(color);
segments.colors.push(color);
var material = new THREE.LineBasicMaterial({
vertexColors: THREE.VertexColors
strokes = new THREE.LineSegments(segments, material);
planet.add(strokes);
function render(a) {
requestAnimationFrame(render);
strokes.geometry.verticesNeedUpdate =
planet.rotation.x += 0.001;
planet.rotation.y += 0.002;
renderer.render(scene, camera);
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或在 SegmentFault,学习技能、解决问题
每个月,我们帮助 1000 万的开发者解决各种各样的技术问题。并助力他们在技术能力、职业生涯、影响力上获得提升。
问题对人有帮助,内容完整,我也想知道答案
问题没有实际价值,缺少关键内容,没有改进余地
/鼠标滚珠上下滑动/var topx = 0var status = 0;$(window).bind('mousewheel DOMMouseScroll', function(event) {
var obj = $("div.sectionwrap");
**var num = obj.attr('data-num') * 1;
var winHeight = $(window).height();
if (event.originalEvent.wheelDelta & 0 || event.originalEvent.detail & 0) {** //向上滑动
if (num & 0 && status == 0) {
status = 1;
topx = -(num - 1) * winH
obj.css('top', topx + "px");
$('#zhuangt li').find('span').removeClass('select');
$('#zhuangt li').eq(num - 1).find('span').addClass('select');
setTimeout(function() {
status = 0;
obj.attr('data-num', num - 1);
if (num === 4) {
$('.nextbtn').find('i').attr('class', 'fa fa-angle-down');
if (num & 4 && status == 0) {
status = 1;
topx = -(num + 1) * winH
obj.css('top', topx + "px");
$('#zhuangt li').find('span').removeClass('select');
$('#zhuangt li').eq(num + 1).find('span').addClass('select');
setTimeout(function() {
status = 0;
obj.attr('data-num', num + 1);
&!-- 0开始,N-2 --&
if (num === 3) {
$('.nextbtn').find('i').attr('class', 'fa fa-angle-up');
});不懂为什么加“originalEvent”,另外再问一下“*1”是有什么用?求大神解答。
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
jquery中,最终传入事件处理程序的 event 其实已经被 jQuery 做过标准化处理
**其原有的事件对象则被保存于 event 对象的 originalEvent 属性之中**
每个 event 都是 jQuery.Event 的实例
所以event.originalEvent.wheelDelta就是指向原始的事件对象
同步到新浪微博
分享到微博?
关闭理由:
删除理由:
忽略理由:
推广(招聘、广告、SEO 等)方面的内容
与已有问题重复(请编辑该提问指向已有相同问题)
答非所问,不符合答题要求
宜作评论而非答案
带有人身攻击、辱骂、仇恨等违反条款的内容
无法获得确切结果的问题
非开发直接相关的问题
非技术提问的讨论型问题
其他原因(请补充说明)
我要该,理由是:
在 SegmentFault,学习技能、解决问题
每个月,我们帮助 1000 万的开发者解决各种各样的技术问题。并助力他们在技术能力、职业生涯、影响力上获得提升。他的最新文章
他的热门文章
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)}

我要回帖

更多关于 event undefined 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信