⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 effects.js

📁 scriptaculous是ajax的一个框架
💻 JS
📖 第 1 页 / 共 3 页
字号:
// script.aculo.us effects.js v1.8.2, Tue Nov 18 18:30:58 +0100 2008// Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)// Contributors://  Justin Palmer (http://encytemedia.com/)//  Mark Pilgrim (http://diveintomark.org/)//  Martin Bialasinki//// script.aculo.us is freely distributable under the terms of an MIT-style license.// For details, see the script.aculo.us web site: http://script.aculo.us/// converts rgb() and #xxx to #xxxxxx format,// returns self (or first argument) if not convertableString.prototype.parseColor = function() {  var color = '#';  if (this.slice(0,4) == 'rgb(') {    var cols = this.slice(4,this.length-1).split(',');    var i=0; do { color += parseInt(cols[i]).toColorPart() } while (++i<3);  } else {    if (this.slice(0,1) == '#') {      if (this.length==4) for(var i=1;i<4;i++) color += (this.charAt(i) + this.charAt(i)).toLowerCase();      if (this.length==7) color = this.toLowerCase();    }  }  return (color.length==7 ? color : (arguments[0] || this));};/*--------------------------------------------------------------------------*/Element.collectTextNodes = function(element) {  return $A($(element).childNodes).collect( function(node) {    return (node.nodeType==3 ? node.nodeValue :      (node.hasChildNodes() ? Element.collectTextNodes(node) : ''));  }).flatten().join('');};Element.collectTextNodesIgnoreClass = function(element, className) {  return $A($(element).childNodes).collect( function(node) {    return (node.nodeType==3 ? node.nodeValue :      ((node.hasChildNodes() && !Element.hasClassName(node,className)) ?        Element.collectTextNodesIgnoreClass(node, className) : ''));  }).flatten().join('');};Element.setContentZoom = function(element, percent) {  element = $(element);  element.setStyle({fontSize: (percent/100) + 'em'});  if (Prototype.Browser.WebKit) window.scrollBy(0,0);  return element;};Element.getInlineOpacity = function(element){  return $(element).style.opacity || '';};Element.forceRerendering = function(element) {  try {    element = $(element);    var n = document.createTextNode(' ');    element.appendChild(n);    element.removeChild(n);  } catch(e) { }};/*--------------------------------------------------------------------------*/var Effect = {  _elementDoesNotExistError: {    name: 'ElementDoesNotExistError',    message: 'The specified DOM element does not exist, but is required for this effect to operate'  },  Transitions: {    linear: Prototype.K,    sinoidal: function(pos) {      return (-Math.cos(pos*Math.PI)/2) + .5;    },    reverse: function(pos) {      return 1-pos;    },    flicker: function(pos) {      var pos = ((-Math.cos(pos*Math.PI)/4) + .75) + Math.random()/4;      return pos > 1 ? 1 : pos;    },    wobble: function(pos) {      return (-Math.cos(pos*Math.PI*(9*pos))/2) + .5;    },    pulse: function(pos, pulses) {      return (-Math.cos((pos*((pulses||5)-.5)*2)*Math.PI)/2) + .5;    },    spring: function(pos) {      return 1 - (Math.cos(pos * 4.5 * Math.PI) * Math.exp(-pos * 6));    },    none: function(pos) {      return 0;    },    full: function(pos) {      return 1;    }  },  DefaultOptions: {    duration:   1.0,   // seconds    fps:        100,   // 100= assume 66fps max.    sync:       false, // true for combining    from:       0.0,    to:         1.0,    delay:      0.0,    queue:      'parallel'  },  tagifyText: function(element) {    var tagifyStyle = 'position:relative';    if (Prototype.Browser.IE) tagifyStyle += ';zoom:1';    element = $(element);    $A(element.childNodes).each( function(child) {      if (child.nodeType==3) {        child.nodeValue.toArray().each( function(character) {          element.insertBefore(            new Element('span', {style: tagifyStyle}).update(              character == ' ' ? String.fromCharCode(160) : character),              child);        });        Element.remove(child);      }    });  },  multiple: function(element, effect) {    var elements;    if (((typeof element == 'object') ||        Object.isFunction(element)) &&       (element.length))      elements = element;    else      elements = $(element).childNodes;    var options = Object.extend({      speed: 0.1,      delay: 0.0    }, arguments[2] || { });    var masterDelay = options.delay;    $A(elements).each( function(element, index) {      new effect(element, Object.extend(options, { delay: index * options.speed + masterDelay }));    });  },  PAIRS: {    'slide':  ['SlideDown','SlideUp'],    'blind':  ['BlindDown','BlindUp'],    'appear': ['Appear','Fade']  },  toggle: function(element, effect) {    element = $(element);    effect = (effect || 'appear').toLowerCase();    var options = Object.extend({      queue: { position:'end', scope:(element.id || 'global'), limit: 1 }    }, arguments[2] || { });    Effect[element.visible() ?      Effect.PAIRS[effect][1] : Effect.PAIRS[effect][0]](element, options);  }};Effect.DefaultOptions.transition = Effect.Transitions.sinoidal;/* ------------- core effects ------------- */Effect.ScopedQueue = Class.create(Enumerable, {  initialize: function() {    this.effects  = [];    this.interval = null;  },  _each: function(iterator) {    this.effects._each(iterator);  },  add: function(effect) {    var timestamp = new Date().getTime();    var position = Object.isString(effect.options.queue) ?      effect.options.queue : effect.options.queue.position;    switch(position) {      case 'front':        // move unstarted effects after this effect        this.effects.findAll(function(e){ return e.state=='idle' }).each( function(e) {            e.startOn  += effect.finishOn;            e.finishOn += effect.finishOn;          });        break;      case 'with-last':        timestamp = this.effects.pluck('startOn').max() || timestamp;        break;      case 'end':        // start effect after last queued effect has finished        timestamp = this.effects.pluck('finishOn').max() || timestamp;        break;    }    effect.startOn  += timestamp;    effect.finishOn += timestamp;    if (!effect.options.queue.limit || (this.effects.length < effect.options.queue.limit))      this.effects.push(effect);    if (!this.interval)      this.interval = setInterval(this.loop.bind(this), 15);  },  remove: function(effect) {    this.effects = this.effects.reject(function(e) { return e==effect });    if (this.effects.length == 0) {      clearInterval(this.interval);      this.interval = null;    }  },  loop: function() {    var timePos = new Date().getTime();    for(var i=0, len=this.effects.length;i<len;i++)      this.effects[i] && this.effects[i].loop(timePos);  }});Effect.Queues = {  instances: $H(),  get: function(queueName) {    if (!Object.isString(queueName)) return queueName;    return this.instances.get(queueName) ||      this.instances.set(queueName, new Effect.ScopedQueue());  }};Effect.Queue = Effect.Queues.get('global');Effect.Base = Class.create({  position: null,  start: function(options) {    function codeForEvent(options,eventName){      return (        (options[eventName+'Internal'] ? 'this.options.'+eventName+'Internal(this);' : '') +        (options[eventName] ? 'this.options.'+eventName+'(this);' : '')      );    }    if (options && options.transition === false) options.transition = Effect.Transitions.linear;    this.options      = Object.extend(Object.extend({ },Effect.DefaultOptions), options || { });    this.currentFrame = 0;    this.state        = 'idle';    this.startOn      = this.options.delay*1000;    this.finishOn     = this.startOn+(this.options.duration*1000);    this.fromToDelta  = this.options.to-this.options.from;    this.totalTime    = this.finishOn-this.startOn;    this.totalFrames  = this.options.fps*this.options.duration;    this.render = (function() {      function dispatch(effect, eventName) {        if (effect.options[eventName + 'Internal'])          effect.options[eventName + 'Internal'](effect);        if (effect.options[eventName])          effect.options[eventName](effect);      }      return function(pos) {        if (this.state === "idle") {          this.state = "running";          dispatch(this, 'beforeSetup');          if (this.setup) this.setup();          dispatch(this, 'afterSetup');        }        if (this.state === "running") {          pos = (this.options.transition(pos) * this.fromToDelta) + this.options.from;          this.position = pos;          dispatch(this, 'beforeUpdate');          if (this.update) this.update(pos);          dispatch(this, 'afterUpdate');        }      };    })();    this.event('beforeStart');    if (!this.options.sync)      Effect.Queues.get(Object.isString(this.options.queue) ?        'global' : this.options.queue.scope).add(this);  },  loop: function(timePos) {    if (timePos >= this.startOn) {      if (timePos >= this.finishOn) {        this.render(1.0);        this.cancel();        this.event('beforeFinish');        if (this.finish) this.finish();        this.event('afterFinish');        return;      }      var pos   = (timePos - this.startOn) / this.totalTime,          frame = (pos * this.totalFrames).round();      if (frame > this.currentFrame) {        this.render(pos);        this.currentFrame = frame;      }    }  },  cancel: function() {    if (!this.options.sync)      Effect.Queues.get(Object.isString(this.options.queue) ?        'global' : this.options.queue.scope).remove(this);    this.state = 'finished';  },  event: function(eventName) {    if (this.options[eventName + 'Internal']) this.options[eventName + 'Internal'](this);    if (this.options[eventName]) this.options[eventName](this);  },  inspect: function() {    var data = $H();    for(property in this)      if (!Object.isFunction(this[property])) data.set(property, this[property]);    return '#<Effect:' + data.inspect() + ',options:' + $H(this.options).inspect() + '>';  }});Effect.Parallel = Class.create(Effect.Base, {  initialize: function(effects) {    this.effects = effects || [];    this.start(arguments[1]);  },  update: function(position) {    this.effects.invoke('render', position);  },  finish: function(position) {    this.effects.each( function(effect) {      effect.render(1.0);      effect.cancel();      effect.event('beforeFinish');      if (effect.finish) effect.finish(position);      effect.event('afterFinish');    });  }});Effect.Tween = Class.create(Effect.Base, {  initialize: function(object, from, to) {    object = Object.isString(object) ? $(object) : object;    var args = $A(arguments), method = args.last(),      options = args.length == 5 ? args[3] : null;    this.method = Object.isFunction(method) ? method.bind(object) :      Object.isFunction(object[method]) ? object[method].bind(object) :      function(value) { object[method] = value };    this.start(Object.extend({ from: from, to: to }, options || { }));  },  update: function(position) {    this.method(position);  }});Effect.Event = Class.create(Effect.Base, {  initialize: function() {    this.start(Object.extend({ duration: 0 }, arguments[0] || { }));  },  update: Prototype.emptyFunction});Effect.Opacity = Class.create(Effect.Base, {  initialize: function(element) {    this.element = $(element);    if (!this.element) throw(Effect._elementDoesNotExistError);    // make this work on IE on elements without 'layout'    if (Prototype.Browser.IE && (!this.element.currentStyle.hasLayout))      this.element.setStyle({zoom: 1});    var options = Object.extend({      from: this.element.getOpacity() || 0.0,      to:   1.0    }, arguments[1] || { });    this.start(options);  },  update: function(position) {    this.element.setOpacity(position);  }});Effect.Move = Class.create(Effect.Base, {  initialize: function(element) {    this.element = $(element);    if (!this.element) throw(Effect._elementDoesNotExistError);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -