最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
javascript div 渐变
时间:2010-07-05 编辑:简简单单 来源:一聚教程网
// 透明度渐变
function changeopacity() {
// 透明度渐变 从1 - 0 渐变时间1000ms
var fx = 'opacity', from = 1, to = 0, time = 1000;
// 渐变完毕执行的回调函数
var callback = function() {
from = 0; to = 1;
new animate(demo, fx, { from: from, to: to, time: time, callback: resetbutton}).start();
}
// 实例化渐变函数
new animate(demo, fx, {
from: from,
to: to,
time: time,
callback: callback
}).start();
}
function animate(el, prop, opts) {
this.el = el;
this.prop = prop;
this.from = opts.from;
this.to = opts.to;
this.time = opts.time;
this.callback = opts.callback;
this.animdiff = this.to - this.from;
}
animate.prototype._setstyle = function(val) {
switch(this.prop) {
case 'opacity':
this.el.style[this.prop] = val;
this.el.style.filter = 'alpha(opacity=' + val * 100 + ')';
break;
default:
this.el.style[this.prop] = val + 'px';
break;
}
}
animate.prototype._animate = function() {
var that = this;
this.now = new date();
this.diff = this.now - this.starttime;
if (this.diff > this.time) {
this._setstyle(this.to);
if (this.callback) {
this.callback.call(this);
}
clearinterval(this.timer);
return;
}
this.percentage = (math.floor((this.diff / this.time) * 100) / 100);
this.val = (this.animdiff * this.percentage) + this.from;
this._setstyle(this.val);
}
animate.prototype.start = function() {
var that = this;
this.starttime = new date();
clearinterval(this.timer);
this.timer = setinterval(function() {
that._animate.call(that);
}, 4);
}
animate.cantransition = function() {
var el = document.createelement('foo');
el.style.css教程text = '-webkit-transition: all .5s linear;';
return !!el.style.webkittransitionproperty;
}();
-
上一个: 阴止页面被其它网站iframe调用代码
-
下一个: 利用jquery插件制作Tabs切换教程
相关文章
- 无线网连接提示没有有效的IP配置解决方法 03-08
- javascript实现下雨效果 07-28
- javascript实现圣旨卷轴展开效果(代码分享) 07-20
- JavaScript实现星星等级评价功能 07-14
- javascript实现滑动解锁功能 07-14
- 十大热门的JavaScript框架和库 07-13