WEB开发网
开发学院网页设计JavaScript prototype使用学习手册指南之Position.js 阅读

prototype使用学习手册指南之Position.js

 2010-09-14 13:11:45 来源:WEB开发网   
核心提示: //判断指定的位置是否在元素内within: function(element, x, y) {if (this.includeScrollOffsets) return this.withinIncludingScrolloffsets(element, x, y);this.xcomp

//判断指定的位置是否在元素内

 within: function(element, x, y) {
  if (this.includeScrollOffsets)
   return this.withinIncludingScrolloffsets(element, x, y);
  this.xcomp = x;
  this.ycomp = y;
  this.offset = this.cumulativeOffset(element);
  return (y >= this.offset[1] &&
       y < this.offset[1] + element.offsetHeight &&
       x >= this.offset[0] &&
       x < this.offset[0] + element.offsetWidth);
 },

//跟within差不多,不过考虑到滚动条,也许是在元素上面,但不是直接在上面,因为滚动条也许已经使元素不可见了 

withinIncludingScrolloffsets: function(element, x, y) {
  var offsetcache = this.realOffset(element);
  this.xcomp = x + offsetcache[0] - this.deltaX;
  this.ycomp = y + offsetcache[1] - this.deltaY;
  this.offset = this.cumulativeOffset(element);
  return (this.ycomp >= this.offset[1] &&
       this.ycomp < this.offset[1] + element.offsetHeight &&
       this.xcomp >= this.offset[0] &&
       this.xcomp < this.offset[0] + element.offsetWidth);
 },
 // within must be called directly before

//在调用这个方法前,必须先调用within,返回在with指定的位置在水平或者垂直方向上占用的百分比

 overlap: function(mode, element) { 
  if (!mode) return 0; 
  if (mode == 'vertical’)
   return ((this.offset[1] + element.offsetHeight) - this.ycomp) /
    element.offsetHeight;
  if (mode == 'horizontal’)
   return ((this.offset[0] + element.offsetWidth) - this.xcomp) /
    element.offsetWidth;
 },

上一页  1 2 3 4 5 6  下一页

Tags:prototype 使用 学习

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接