仿GOOGLE的Javascript动画

本文介绍了一个简单的自制播放器实现方案,通过定义Player类并实现控制方法来模拟播放效果。该播放器支持基本的播放、暂停及跳转等功能。
导读:
  效果和GOOGLE的一样,只是具体实现方式有点不一样,各有利弊。
  这里定义了一个Player类,并实现了一些简单的控制方法,有兴趣的可以自己扩展
  // JavaScript Player// Author:Radish(Robin Chen) QQ:4705648 MSN:robchen@126.com EMAIL:robchen@126.comfunction 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
  Trackback: http://tb.blog.youkuaiyun.com/TrackBack.aspx?PostId=1636293

本文转自
http://blog.youkuaiyun.com/rob123/archive/2007/06/03/1636293.aspx
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值