仿GOOGLE的Javascript动画

效果和GOOGLE的一样,只是具体实现方式有点不一样,各有利弊。

这里定义了一个Player类,并实现了一些简单的控制方法,有兴趣的可以自己扩展

//  JavaScript Player
//
 Author:Radish(Robin Chen) QQ:4705648 MSN:robchen@126.com EMAIL:robchen@126.com

function  Player(movieClips,interval,containter) {
    
var uniqueID = Math.round(Math.random()*1000);
    
while(window[uniqueID]){
        uniqueID 
++;
    }

    
this.uniqueID = uniqueID;
    
this.timeLine = movieClips;
    
this.containter = containter;
    
this.interval = interval;
    
this.currentFrame = 0;
    
this.playMode = 0;
}

Player.prototype 
=   {
    play:
function(){
        
if(this.currentFrame >= this.timeLine.length){
            
this.currentFrame = this.timeLine.length - 1;
            
this.stop();
            
return;
        }
else if(this.currentFrame < 0){
            
this.currentFrame = 0;
            
this.stop();
            
return;
        }

        
this.showMovie();
        
if(this.playMode == 0){
            
this.currentFrame ++;
        }
else{
            
this.currentFrame --;
        }

        
var _this = this;
        window[
this.uniqueID] = window.setTimeout(function(){_this.play();},this.interval);
    }
,
    stop:
function(){
        window.clearTimeout(window[
this.uniqueID]);
    }
,
    gotoAndStop:
function(frame){
        
if(frame < 0)frame = this.timeLine.length + frame;
        frame 
= (frame >= this.timeLine.length)?this.timeLine.length-1:frame;
        
this.currentFrame = frame;
        
this.showMovie();
        
this.stop();
    }
,
    gotoAndPlay:
function(frame){
        
if(frame < 0)frame = this.timeLine.length + frame;
        frame 
= (frame > this.timeLine.length)?this.timeLine.length:frame;
        
this.currentFrame = frame;
        
this.showMovie();
        
this.play();
    }
,
    showMovie:
function(){
        
if(this.containter.tagName.toLowerCase() == "img"){
            
this.containter.src = this.timeLine[this.currentFrame].src;
        }
else{
            
this.containter.style.backgroundImage = this.timeLine[this.currentFrame].src;
        }

    }

}
 
本文效果的演示地址如下:
http://www.robchen.cn/jsplayer/

GOOGLE的效果演示:
http://www.google.co.kr/ig?sp=korea&hl=ko
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值