时间:2009年09月30日作者:愚人码头查看次数:3,486 views评论次数:3
上接http://www.css88.com/archives/1910
这里新加了一个extend方法.
function extend(des, src) {
if (!des) {
des = {};
}
if (src) {
for (var i in src) {
des[i] = src[i];
}
}
return des;
}
function MagicColor(elem,colors,interTime){
this.elements=elem||[];
this.colors=colors||["#CC0000","#CC6D00","#CCCC00","#00CC00","#0000CC","#00CCCC","#CC00CC"];
this.indexColors=0;
this.interTime=interTime;
}
extend(MagicColor.prototype,{
timerCall:function (){
var elem=this.elements;
var color=this.colors[(this.indexColors++)%this.colors.length];
for(var i=0;i<elem.length;i++){
elem[i].style.color=color;
}
},
reset : function(){
if(this.timer){
clearInterval(this.timer);
delete this.timer;
}
},
start:function(){
this.reset();
var self=this;
this.timer= setInterval( function(){
self.timerCall();
},this.interTime||100);
}
});
调用还是:
function $(id){return document.getElementById(id)}
var effect = new MagicColor([$("comment1"),$("comment2"),$("comment3")],["#000000","#CC0000","#C00000","#00CC00","#0000CC","#00CCCC","#CC00CC"],500);
effect.start();
时间:2009年09月30日作者:愚人码头查看次数:4,347 views评论次数:3
这是一题知名公司的前端开发面试试题,要求写出闪光字的效果。基本思路是:
1.页面中可能多出使用;
2.选出几种颜色;
3.选择合理的跳动时间。
例如html代码
<div id="comment1">愚人码头</div>
<div id="comment2">前端开发</div>
<div id="comment3">http://www.css88.com</div>
javascript代码:
function MagicColor(elem,colors,interTime){
this.elements=elem||[];
this.colors=colors||["#CC0000","#CC6D00","#CCCC00","#00CC00","#0000CC","#00CCCC","#CC00CC"];//可选的颜色值
this.indexColors=0;//颜色值索引
this.interTime=interTime;//跳动的间隔时间
}
MagicColor.prototype.timerCall=function(){
var elem=this.elements,cls=this.colors;
var color=this.colors[(this.indexColors++) % this.colors.length];//去除当前颜色
for(var i=0;i<elem .length;i++){
elem[i].style.color=color;
}
};
MagicColor.prototype.reset=function(){
if(this.timer){
clearInterval(this.timer);
delete this.timer;
}
};
MagicColor.prototype.start=function(){
this.reset();
var self=this;
this.timer = setInterval(function(){
self.timerCall();
},self.interTime||100);
}
function $(id){return document.getElementById(id)}
var effect = new MagicColor([$("comment1"),$("comment2"),$("comment3")],["#000000","#CC0000","#C00000","#00CC00","#0000CC","#00CCCC","#CC00CC"],500);
effect.start();
感谢肉块的指教,欢迎大家拍砖。
下接:http://www.css88.com/archives/1921
最新评论
非常好
Post:2012-02-08 21:59:12@linda, 没见过世面吧你,老板才8 »
Post:2012-02-07 18:11:22码头哥,换个链接,http://www.ijo »
Post:2012-02-07 17:18:45currying: 科里化
Post:2012-02-06 15:51:18貌似在线api已经下不了了
Post:2012-02-06 11:25:19图片被防盗链了,哈哈~
Post:2012-02-06 10:29:45对你造成的不便非常抱歉,简易你卸 »
Post:2012-02-05 14:45:16您好,请问air版本的自动更新怎么去 »
Post:2012-02-05 12:06:24