這篇文章主要介紹了JS功能代碼集錦 的相關(guān)資料,需要的朋友可以參考下
1.模仿fade in(),fade out().
原理:setInterval ( "opacity++透明度“函數(shù),時(shí)間間隔)
var alpha = 0;
function play(){
timer = setInterval(function(){
alpha += 2;
alpha > 100 && (alpha = 100);
aImg[index].style.opacity = alpha / 100;
aImg[index].style.filter = "alpha(opacity = " + alpha/100 + ")";
alpha == 100 && clearInterval(timer);
},40)
}
2.獲取和設(shè)置元素對(duì)象的屬性值:
關(guān)鍵點(diǎn):obj.currentStyle[attr] ; getComputedStyle(obj,null)[attr] ;
function css(obj,attr,val) {
switch(arguments.length) {
case 2:
if(typeof arguments[1] == "string"){
return obj.currentStyle ? obj.currentStyle[attr] : getComputedStyle(obj,null)[attr];
}else{
for(var i in attr) {
obj.style[i] = attr[i];
}
}
break;
case 3:
obj.style[attr] = val;
break;
default:
alert("錯(cuò)誤參數(shù)");
}
}
以上所述是小編給大家介紹的JS功能代碼集錦的相關(guān)內(nèi)容,希望對(duì)大家有所幫助!