注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

火山左儿

学无止境

 
 
 

日志

 
 

as2 滚动条  

2011-11-11 17:17:26|  分类: flash全站学习 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

//copyright by webstudio.com.cn author by egoldy.
Stage.scaleMode = "showAll";
System.useCodepage = false;


function scrolling(easing, auto, mouse) {
//滚动速度
var moveSpeed = 1;
var easingSpeed = 10;
var scrollHeight = scrollbg._height;
//可滚动的区域
var scrollable = contentMain._height-maskedView._height;
var top_scroll = contentMain._y;
//滑块可拖动的区域
var left = scrollbg._x;
var top = scrollbg._y;
var right = scrollbg._x;
var bottom = scrollbg._y+scrollbg._height-dragger._height;
//在开始前检测我们的滚动是否可滚动,如果内容不足滚动,隐藏dragger等,并返回。
if (scrollable<0) {
   dragger._visible = false;
   btnup._alpha = 50;
   btndown._alpha = 50;
   scrollbg._alpha = 50;
   btnup.enabled = false;
   btndown.enabled = false;
   return;
}
//更新滚动内容的位置。公式的应用    
function updateContentPos() {
   var percent_scrolled = (dragger._y-btnup._height)/(scrollHeight-dragger._height);
   contentMain.newY = Math.round(top_scroll-(scrollable*percent_scrolled));
   trace(contentMain.newY);
}
contentMain.onEnterFrame = function() {
   if (!easing || easing == undefined) {
    this._y = this.newY;
   } else {
    this._y += (this.newY-this._y)/easingSpeed;
   }
};
//拖动滑块
dragger.onPress = function() {
   startDrag(this, false, left, top, right, bottom);
   this.onMouseMove = function() {
    updateContentPos();
   };
};
dragger.onRelease = dragger.onReleaseOutside=function () {
   stopDrag();
   delete this.onEnterFrame;
};
btnup.onPress = function() {
   this.onEnterFrame = function() {
    //技巧
    dragger._y = Math.max(top, dragger._y-moveSpeed);
    updateContentPos();
   };
};
btnup.onRelease = function() {
   delete this.onEnterFrame;
};
btndown.onPress = function() {
   this.onEnterFrame = function() {
    dragger._y = Math.min(bottom, dragger._y+moveSpeed);
    updateContentPos();
   };
};
btndown.onRelease = function() {
   delete this.onEnterFrame;
};
updateContentPos();
//++++++++++++++++++++++++++++++++++++++++++
//自动滚动代码段
if (auto == true) {
   onEnterFrame = function () {
    if (dragger._y<bottom) {
     dragger._y = dragger._y+0.2;
     updateContentPos();
    } else {
     dragger._y = top;
    }
   };
}
//+++++++++++++++++++++++++++++++++++++++++++
//中键滚动代码段
if (mouse == true) {
   var mouseListener = new Object();
   //创建onMouseWheel函数
   mouseListener.onMouseWheel = function(delta) {
    if (dragger._y<bottom) {
     dragger._y += delta;
     updateContentPos();
    } else {
     dragger._y = bottom;
    }
    if (dragger._y>top) {
     dragger._y += delta;
     updateContentPos();
    } else {
     dragger._y = top;
    }
   };
   Mouse.addListener(mouseListener);
}
//++++++++++++++++++++++++++++++++++++++++++++
}
//调用函数
scrolling(true, false, true);


  评论这张
 
阅读(972)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018