用ajax.net封装的不间断marquee行为
/// <reference name="MicrosoftAjax.js"/>
Type.registerNamespace("DDT");
DDT.Direction = function(){};
DDT.Direction.prototype = {
Left:0,
Right:1,
Up:2,
Down:3
}
DDT.Direction.registerEnum("DDT.Direction");
DDT.Marqee = function(element) {
DDT.Marqee.initializeBase(this, [element]);
this.EnumDirection = DDT.Direction.Left;
this.Speed = 30;
this.TimeId = null;
}
DDT.Marqee.prototype = {
initialize: function() {
DDT.Marqee.callBaseMethod(this, 'initialize');
this.get_element().innerHTML += this.get_element().innerHTML;
this.get_element().style.overflow = "hidden";
if(this.EnumDirection==DDT.Direction.Left||this.EnumDirection==DDT.Direction.Right)
{
this.get_element().style.whiteSpace="nowrap";
}
this._onMouseOverHandler = Function.createDelegate(this,this._onMouseOver);
this._onMouseOutHandler = Function.createDelegate(this,this._onMouseOut);
this._onMarqeeHandler = Function.createDelegate(this,this._onMarqee);
$addHandler(this.get_element(), "mouseover",this._onMouseOverHandler);
$addHandler(this.get_element(), "mouseout",this._onMouseOutHandler);
this.TimeId = setInterval(this._onMarqeeHandler,this.Speed);
// Add custom initialization here
},_onMarqee:function(){
switch(this.EnumDirection)
{
case DDT.Direction.Right:
if(this.get_element().scrollLeft<=0){
this.get_element().scrollLeft = this.get_element().scrollWidth/2;
}else{
this.get_element().scrollLeft --;
}
break;
case DDT.Direction.Up:
if(this.get_element().scrollTop>=(this.get_element().scrollHeight) /2){
this.get_element().scrollTop = 0;
}else{
this.get_element().scrollTop ++;
}
break;
case DDT.Direction.Down:
if(this.get_element().scrollTop<=0){
this.get_element().scrollTop = (this.get_element().scrollHeight) /2;
}else{
this.get_element().scrollTop --;
}
break;
default:
if(this.get_element().scrollLeft>=this.get_element().scrollWidth/2){
this.get_element().scrollLeft = 0;
}else{
this.get_element().scrollLeft ++;
}
break;
}
},_onMouseOver:function(){
clearInterval(this.TimeId);
},_onMouseOut:function(){
this.TimeId = setInterval(this._onMarqeeHandler,this.Speed);
},
dispose: function() {
//Add custom dispose actions here
DDT.Marqee.callBaseMethod(this, 'dispose');
}
}
DDT.Marqee.registerClass('DDT.Marqee', Sys.UI.Behavior);
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
使用方法:Type.registerNamespace("DDT");
DDT.Direction = function(){};
DDT.Direction.prototype = {
Left:0,
Right:1,
Up:2,
Down:3
}
DDT.Direction.registerEnum("DDT.Direction");
DDT.Marqee = function(element) {
DDT.Marqee.initializeBase(this, [element]);
this.EnumDirection = DDT.Direction.Left;
this.Speed = 30;
this.TimeId = null;
}
DDT.Marqee.prototype = {
initialize: function() {
DDT.Marqee.callBaseMethod(this, 'initialize');
this.get_element().innerHTML += this.get_element().innerHTML;
this.get_element().style.overflow = "hidden";
if(this.EnumDirection==DDT.Direction.Left||this.EnumDirection==DDT.Direction.Right)
{
this.get_element().style.whiteSpace="nowrap";
}
this._onMouseOverHandler = Function.createDelegate(this,this._onMouseOver);
this._onMouseOutHandler = Function.createDelegate(this,this._onMouseOut);
this._onMarqeeHandler = Function.createDelegate(this,this._onMarqee);
$addHandler(this.get_element(), "mouseover",this._onMouseOverHandler);
$addHandler(this.get_element(), "mouseout",this._onMouseOutHandler);
this.TimeId = setInterval(this._onMarqeeHandler,this.Speed);
// Add custom initialization here
},_onMarqee:function(){
switch(this.EnumDirection)
{
case DDT.Direction.Right:
if(this.get_element().scrollLeft<=0){
this.get_element().scrollLeft = this.get_element().scrollWidth/2;
}else{
this.get_element().scrollLeft --;
}
break;
case DDT.Direction.Up:
if(this.get_element().scrollTop>=(this.get_element().scrollHeight) /2){
this.get_element().scrollTop = 0;
}else{
this.get_element().scrollTop ++;
}
break;
case DDT.Direction.Down:
if(this.get_element().scrollTop<=0){
this.get_element().scrollTop = (this.get_element().scrollHeight) /2;
}else{
this.get_element().scrollTop --;
}
break;
default:
if(this.get_element().scrollLeft>=this.get_element().scrollWidth/2){
this.get_element().scrollLeft = 0;
}else{
this.get_element().scrollLeft ++;
}
break;
}
},_onMouseOver:function(){
clearInterval(this.TimeId);
},_onMouseOut:function(){
this.TimeId = setInterval(this._onMarqeeHandler,this.Speed);
},
dispose: function() {
//Add custom dispose actions here
DDT.Marqee.callBaseMethod(this, 'dispose');
}
}
DDT.Marqee.registerClass('DDT.Marqee', Sys.UI.Behavior);
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
$create(DDT.Marqee,{Speed:30,EnumDirection:DDT.Direction.Right},null,null,$get("UserScoreScroll"));
posted on 2008-03-13 16:56 jueban's space 阅读(352) 评论(0) 收藏 举报
浙公网安备 33010602011771号