其次说说目的:
瞎玩,纯粹为了学习js练习作。
呃,最后ps:偷偷借鉴了某人写的一个函数:返回最终样式函数。
*{margin:0;padding:0;}
body { padding:1em; }
h2 { font-size:2em; }
div { display:inline-block; width:10em; padding:.5em; margin-bottom:1em; overflow:hidden; background:#eee; text-align:center; font-size:1em; }
p#text { position:absolute; right:10px; top:10px; }
标题
测试鼠标滑动效果
标题
测试鼠标滑动效果
标题
测试鼠标滑动效果
标题
测试鼠标滑动效果
function getdefaultstyle(obj,attribute){ //返回最终样式函数,兼容ie和dom,设置参数:元素对象、样式特性
return obj.currentstyle?obj.currentstyle[attribute]:document.defaultview.getcomputedstyle(obj,false)[attribute];
}
function pr_box(id,e){
clearinterval(document.getelementbyid(id).maxmin);
var obj=document.getelementbyid(id);
var cfont=getdefaultstyle(obj,"fontsize");// 得到默认的大小:附单位
var cp=cfont.replace(/[0-9]|[\.]/g,"");// 得到默认的单位
var fsize=parsefloat(cfont);// 得到默认的大小数值
var s=10;// 运动速度
if(!obj.fsizetmpe){// 存储默认大小数值
obj.fsizetmpe=fsize;
}
if(!objfont){// 如果没有设置当前大小,则赋予其默认大小
obj.style.fontsize = cfont;
}
var e = obj.fsizetmpe*e/100;// 需要改变到的大小数值
var objfont = parsefloat(obj.style.fontsize);// 得到当前的大小
if(e obj.fsizetmpe){obj.maxmin = setinterval(function(){pr_max(obj,e,cp)},s);}
if(e == obj.fsizetmpe){
if(objfont obj.fsizetmpe){
obj.maxmin = setinterval(function(){pr_min(obj,obj.fsizetmpe,cp)},s);
}
}
}
function pr_max(obj,e,cp){
if(!obj.fs){
obj.fs=obj.style.fontsize;
}
var objfont=parsefloat(obj.fs);
if(e > objfont){
//document.getelementbyid("text").innerhtml+="放大 - 原始值:"+objfont+" + 递增值:"+e/10+"[br /]";
obj.fs = objfont+e/10+cp;
obj.style.fontsize = obj.fs;
}
else if(e < objfont){
obj.fs = e+cp;
obj.style.fontsize = obj.fs;
}
else{clearinterval(obj.maxmin);}
}
function pr_min(obj,e,cp){
if(!obj.fs){
obj.fs=obj.style.fontsize;
}
var objfont=parsefloat(obj.fs);
if(e objfont){
obj.fs = e+cp;
obj.style.fontsize = obj.fs;
}
else{clearinterval(obj.maxmin);}
}
[ctrl+a 全选 注:如需引入外部js需刷新才能执行]