mootools位置切换类

  1. var posSwitch = new Class({
  2.     options :{
  3.         api : 'http://6.cn/6cntest/p/h.html',  //待定
  4.         transition : {duration: 1000,transition: Fx.Transitions.Cubic.easeOut}  
  5.     },
  6.     
  7.     initialize:function(parentId,boxClass,options){
  8.         
  9.         this.setOptions(options);
  10.         this.idArr = [];                 //模块顺序的数组(发送到php端保存的数组)
  11.         this.parentId = parentId;        //模块的总父容器 
  12.         this.boxClass = boxClass;        //模块的class
  13.         this.boxs = $$('#' + this.parentId + ' div.'this.boxClass);      //排序的模块数组
  14.         this.num = this.boxs.length; 
  15.         if(this.num == 0) return;                                     // 排序的模块个数
  16.         for(var i=0; i<this.num; i++){
  17.             var box = this.boxs[i]
  18.            this.idArr.push(box.id);
  19.         }
  20.         $$('#'+this.boxs[0].id + ' p')[0].addClass('top');
  21.         $$('#'+this.boxs[this.num-1].id + ' p')[0].addClass('bottom');
  22.         var uplinks = $$('#' + this.parentId + ' a.up');
  23.         var downlinks = $$('#'this.parentId + ' a.down');
  24.         uplinks.each(function(ele){
  25.             ele.addEvent('click',function(event){event.stop();this.switUp(ele)}.bindWithEvent(this))
  26.             }.bind(this)
  27.          )
  28.         downlinks.each(function(ele){
  29.             ele.addEvent('click',function(event){event.stop();this.switDown(ele)}.bindWithEvent(this))
  30.             }.bind(this)
  31.          )
  32.     },
  33.     
  34.     switDown : function(ele){
  35.         var thisObj = $(ele.parentNode.parentNode);
  36.         var thisIndex = this.idArr.indexOf(thisObj.id);
  37.         var thatObj = $(this.idArr[thisIndex+1]);
  38.         this.idArr[thisIndex] = thatObj.id;
  39.         this.idArr[thisIndex+1] = thisObj.id;
  40.         
  41.         var thisTop = thisObj.getStyle('top') == 'auto' ? 0 : thisObj.getStyle('top').toInt();
  42.         var thatTop = thatObj.getStyle('top') == 'auto' ? 0 : thatObj.getStyle('top').toInt();
  43.         var thisHeight = thisObj.getStyle('height').toInt();    // 块高
  44.         var thatHeight = thatObj.getStyle('height').toInt();
  45.         var e = new Fx.Styles(thisObj, this.options.transition);
  46.         e.start({'top':[thisTop,thisTop+thatHeight],'opacity':[0.5,1]});
  47.         var f = new Fx.Styles(thatObj, this.options.transition);
  48.         f.start({'top':[thatTop, thatTop-thisHeight],'opacity':[0.5,1]});
  49.         this.arrowChange();
  50.     },
  51.     
  52.     switUp : function(ele){
  53.         var thisObj = $(ele.parentNode.parentNode);
  54.         var thisIndex = this.idArr.indexOf(thisObj.id);
  55.         var thatObj = $(this.idArr[thisIndex-1]);
  56.         this.idArr[thisIndex] = thatObj.id;
  57.         this.idArr[thisIndex-1] = thisObj.id;
  58.         
  59.         var thisTop = thisObj.getStyle('top') == 'auto' ? 0 : thisObj.getStyle('top').toInt();
  60.         var thatTop = thatObj.getStyle('top') == 'auto' ? 0 : thatObj.getStyle('top').toInt();
  61.         var thisHeight = thisObj.getStyle('height').toInt();    // 块高
  62.         var thatHeight = thatObj.getStyle('height').toInt();
  63.         var e = new Fx.Styles(thisObj, this.options.transition);
  64.         e.start({'top':[thisTop,thisTop-thatHeight],'opacity':[0.5,1]});
  65.         var f = new Fx.Styles(thatObj, this.options.transition);
  66.         f.start({'top':[thatTop, thatTop+thisHeight],'opacity':[0.5,1]});
  67.         this.arrowChange();
  68.        
  69.     },
  70.     
  71.     arrowChange:function(){
  72.         var links = $$('#'this.parentId + ' a.down, a.up');
  73.         for(var i=0;i<links.length;i++){
  74.            $(links[i].parentNode).removeClass('top').removeClass('bottom');
  75.         }
  76.         $$('#'+this.idArr[0] + ' p')[0].addClass('top');
  77.         $$('#'+this.idArr[this.num-1] + ' p')[0].addClass('bottom');
  78.     
  79.     },
  80.     
  81.     save : function(){
  82.         var url = this.options.api;
  83.         var data = 'order='this.idArr + '&uid=' + pageMessage.uid;
  84.         var callback = this.back.bind(this);
  85.         alert(data);
  86.         Request.reSend(url,data,callback);
  87.     },
  88.     
  89.     back :function(httpobj){
  90.         
  91.     }
  92. })
  93. posSwitch.implement(new Events, new Options);
  94. window.addEvent('load'function(){
  95.      mySwitch = new posSwitch('scrollWrap','myPanelBox');
  96. })
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值