`
指甲刀X
  • 浏览: 33935 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论
收藏列表
标题 标签 来源
对象的深度拷贝 自动执行函数
var deepExtend = function(destination, source) {
  for (var property in source) {
    if (source[property] && source[property].constructor &&
     source[property].constructor === Object) {
      destination[property] = destination[property] || {};
      arguments.callee(destination[property], source[property]);
    } else {
      destination[property] = source[property];
    }
  }
  return destination;
};
Page Size, Scrollbar Position, Viewport Size pro javascript techniques
// Returns the height of the web page
// (could change if new content is added to the page)
function pageHeight() {
return document.body.scrollHeight;
}

// Returns the width of the web page
function pageWidth() {
return document.body.scrollWidth;
}



// A function for determining how far horizontally the browser is scrolled
function scrollX() {
// A shortcut, in case we're using Internet Explorer 6 in Strict Mode
var de = document.documentElement;
// If the pageXOffset of the browser is available, use that
return self.pageXOffset ||
// Otherwise, try to get the scroll left off of the root node
( de && de.scrollLeft ) ||
// Finally, try to get the scroll left off of the body element
document.body.scrollLeft;
}


// A function for determining how far vertically the browser is scrolled
function scrollY() {
// A shortcut, in case we're using Internet Explorer 6 in Strict Mode
var de = document.documentElement;
// If the pageYOffset of the browser is available, use that
return self.pageYOffset ||
// Otherwise, try to get the scroll top off of the root node
( de && de.scrollTop ) ||
// Finally, try to get the scroll top off of the body element
document.body.scrollTop;
}



// Find the height of the viewport
function windowHeight() {
// A shortcut, in case we're using Internet Explorer 6 in Strict Mode
var de = document.documentElement;
// If the innerHeight of the browser is available, use that
return self.innerHeight ||
// Otherwise, try to get the height off of the root node
( de && de.clientHeight ) ||
// Finally, try to get the height off of the body element
document.body.clientHeight;
}


// Find the width of the viewport
function windowWidth() {
// A shortcut, in case we're using Internet Explorer 6 in Strict Mode
var de = document.documentElement;
// If the innerWidth of the browser is available, use that
return self.innerWidth ||
// Otherwise, try to get the width off of the root node
( de && de.clientWidth ) ||
// Finally, try to get the width off of the body element
document.body.clientWidth;
}
mouse position pro javascript techniques
// Find the horizontal position of the cursor
function getX(e) {
// Normalize the event object
e = e || window.event;
// Check for the non-IE position, then the IE position
return e.pageX || e.clientX + document.body.scrollLeft;
}
// Find the vertical position of the cursor
function getY(e) {
// Normalize the event object
e = e || window.event;
// Check for the non-IE position, then the IE position
return e.pageY || e.clientY + document.body.scrollTop;
}



// Get the X position of the mouse relative to the element target
// used in event object 'e'
function getElementX( e ) {
// Find the appropriate element offset
return ( e && e.layerX ) || window.event.offsetX;
}
// Get the Y position of the mouse relative to the element target
// used in event object 'e'
function getElementY( e ) {
// Find the appropriate element offset
return ( e && e.layerY ) || window.event.offsetY;
}
Global site tag (gtag.js) - Google Analytics