js 个人的特效库


/**
* Created by fei on 2016/6/5.
*/
/*获取class,var cda=getClass(document,'da')[0];*/
function getClass(oParent,className){var eLement=document.getElementsByTagName('*');var i=0;var attr=[];for(i=0;i;i++){if(eLement[i].className==className){attr.push(eLement[i]);}}return attr;}
/*设置属性setStyle(da,{backgroundColor:'green',height:'200px'})*/
function setStyle(obj,json){var attr = '';for (attr in json) {obj.style[attr] = json[attr];}}
/*添加CLass addClass(oLi[i],'red') */
function addClass(obj,className){if(obj.className== ''){obj.className=className;}else{var arrClassName = obj.className.split(' ');if ( arrIndexOf(arrClassName, className) == -1 ) {obj.className += ' ' + className;/*arrClassName.push(className);obj.className = arrClassName.join(' ');*/}}}function arrIndexOf(arr, v) {for (var i=0; i; i++) {if (arr[i] == v) {return i;}}return -1;}
/*获取属性兼容iecurrent*/
function getStyle(obj,attr){if(obj.currentStyle){return obj.currentStyle[attr]}else{return getComputedStyle(obj,33)[attr]}}
/*运动框架move(this,{height:111,width:200,opacity:30})*/
function move(obj,json,fn) {clearInterval(obj.timer);obj.timer = setInterval(function () {var mStop=true; /*当所有的值都到达*/for(var attr in json) {/*取当前值*/var com =0;if(attr=='opacity'){com=parseInt(parseFloat(getStyle(obj, attr))*100);}else{com=parseInt(getStyle(obj, attr))}/*计算速度*/var iSpeed = (json[attr] - com) / 8;iSpeed=iSpeed>0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);/*检测*/if(com != json[attr]){mStop=false}if(attr=='opacity'){obj.style.filter='alpha(opacity:'+(com+iSpeed)+')';obj.style.opacity = (com+iSpeed)/100;}else{obj.style[attr] = com + iSpeed + 'px';}}if(mStop){clearInterval(obj.timer);if(fn){fn()}}},30)}
/*删除Class removeClass(oW,"pageShow");*/
function removeClass(obj, sClass) {var aClass = obj.className.split(' ');if (!obj.className) return;for (var i = 0; i < aClass.length; i++) {if (aClass[i] === sClass) {aClass.splice(i, 1);obj.className = aClass.join(' ');break;}}}
/*无滚动轮播wgdlb('warp','ul','li','next','prev',1000);*/
function wgdlb(warp,ul,li,next,prev,setIn) {var oWarp = document.getElementById(warp);var oUl = document.getElementById(ul);var oLi = oUl.getElementsByTagName(li);var oNext = document.getElementById(next);var oPrev = document.getElementById(prev);var num=0;var timer=null;oUl.style.width=oUl.children.length*oUl.children[0].offsetWidth+"px";oNext.onclick=you;oPrev.onclick=zuo;timer=setInterval(function(){you()},setIn);oWarp.onmouseover=function(){clearInterval(timer);};oWarp.onmouseout=function(){timer=setInterval(function(){you()},setIn);};function you(){num++;if(num0].offsetWidth+'px';}else{num=0;oUl.style.marginLeft=num*-oLi[0].offsetWidth+'px';}}function zuo(){num--;if(num<0){num=oLi.length-1;oUl.style.marginLeft=num*-oLi[0].offsetWidth+'px';}else{oUl.style.marginLeft=num*-oLi[0].offsetWidth+'px';}}}
/*有滚动轮播ygdlb2('warp','prev','next','ul',1000);*/
function ygdlb2(warp,prev,next,ul,set){var warp=document.getElementById(warp);var prev=document.getElementById(prev);var next=document.getElementById(next);var ul=document.getElementById(ul);var li=ul.children;var num=0;var timer=null;ul.appendChild(li[0].cloneNode(true));ul.style.width=li[0].offsetWidth*li.length+'px';prev.onclick=zuo;next.onclick=you;clearInterval(timer);timer=setInterval(you,set);warp.onmouseover=function(){clearInterval(timer)};warp.onmouseout=function(){timer=setInterval(you,set);};function zuo(){num--;if(num<0){num=li.length-2;ul.style.marginLeft=-li[0].offsetWidth*(li.length-1)+'px';}move(ul,{marginLeft:-num*li[0].offsetWidth})}function you(){num++;if(num>li.length-1){num=1;ul.style.marginLeft=0;}move(ul,{marginLeft:-num*li[0].offsetWidth});}}
/*带翻页器和class有滚动轮播ygdlb('warp','prev','next','ul','fyq','active',1000);*/
function ygdlb(warp,prev,next,ul,fyq,active,set){var warp=document.getElementById(warp);var prev=document.getElementById(prev);var next=document.getElementById(next);var ul=document.getElementById(ul);var fyq=document.getElementById(fyq);var li=ul.children;var num=0;var fyqnum=0;var timer=null;ul.appendChild(li[0].cloneNode(true));ul.style.width=li[0].offsetWidth*li.length+'px';prev.onclick=zuo;next.onclick=you;for(var i=0;i1;i++){var span=document.createElement('span');fyq.appendChild(span);span.innerHTML=1+i;}clearInterval(timer);timer=setInterval(you,set);warp.onmouseover=function(){clearInterval(timer)};warp.onmouseout=function(){timer=setInterval(you,set);};addClass(fyq.children[0],active);function zuo(){fyqnum--;if(fyqnum<0){fyqnum=li.length-2;}for(var i=0;i1;i++){removeClass(fyq.children[i],active);addClass(fyq.children[fyqnum],active);}num--;if(num<0){num=li.length-2;ul.style.marginLeft=-li[0].offsetWidth*(li.length-1)+'px';}move(ul,{marginLeft:-num*li[0].offsetWidth})}function you(){fyqnum++;if(fyqnum>li.length-2){fyqnum=0;}for(var i=0;i1;i++){removeClass(fyq.children[i],active);addClass(fyq.children[fyqnum],active);}num++;if(num>li.length-1){num=1;ul.style.marginLeft=0;}move(ul,{marginLeft:-num*li[0].offsetWidth});}}
/*移入切换带class yrqh('zzp_bgul','li','zzp_bgol','li');*/
function yrqh(zzp_bgul,uli,zzp_bgol,oli){var oUl=document.getElementById(zzp_bgul);var oUli=oUl.getElementsByTagName(uli);var oOl=document.getElementById(zzp_bgol);var oOli=oOl.getElementsByTagName(oli);var i=0;for(i=0;i;i++){oOli[i].index=i;oUli[i].style.display='none';oUli[0].style.display='block';addClass(oOli[0],'active');oOli[i].onmouseover=function(){for(var j=0;j;j++){oUli[j].style.display='none';removeClass(oOli[j],'active')}oUli[this.index].style.display='block';addClass(oOli[this.index],'active')}}}
/*无缝滚动 wfgd('wfgdul','li',-2)*/
function wfgd(wfgdul,li,speed){var oWfgdul=document.getElementById(wfgdul);var oLi=oWfgdul.getElementsByTagName(li);var timer=null;oWfgdul.innerHTML+=oWfgdul.innerHTML;oWfgdul.style.width=oLi.length*oLi[0].offsetWidth+'px';clearInterval(timer);timer=setInterval(function(){zuo()},30);oWfgdul.onmouseover=function(){clearInterval(timer);};oWfgdul.onmouseout=function(){ timer=setInterval(function(){zuo()},30);};function zuo(){if(oWfgdul.offsetLeft<-oWfgdul.offsetWidth/2){oWfgdul.style.left='0';}else if(oWfgdul.offsetLeft>0){oWfgdul.style.left=-oWfgdul.offsetWidth/2+'px';}oWfgdul.style.left=oWfgdul.offsetLeft+speed+'px';}}
/*滚动固定顶部导航*/
function gdnav(ID){window.onload=function(){var oNav=document.getElementById(ID);var offsetTop=oNav.offsetTop;window.onscroll=function(){var scroll=document.documentElement.scrollTop || document.body.scrollTop;if(scroll>offsetTop){oNav.style.position='fixed';oNav.style.zIndex=1000;oNav.style.top='0';oNav.style.left='0';}else{oNav.style.position='static';}}}}
/*拖拽*/
function drag(obj) {obj.onmousedown = function(ev) {var ev = ev || event;var disX = ev.clientX - this.offsetLeft;var disY = ev.clientY - this.offsetTop;if ( obj.setCapture ) {obj.setCapture();}document.onmousemove = function(ev) {var ev = ev || event;var L = ev.clientX - disX;var T = ev.clientY - disY;if ( L < 0 ) {L = 0;} else if ( L > document.documentElement.clientWidth - obj.offsetWidth ) {L = document.documentElement.clientWidth - obj.offsetWidth;}if ( T < 0 ) {T = 0;} else if ( T > document.documentElement.clientHeight - obj.offsetHeight ) {T = document.documentElement.clientHeight - obj.offsetHeight;}obj.style.left = L + 'px';obj.style.top = T + 'px';};document.onmouseup = function() {document.onmousemove = document.onmouseup = null;if ( obj.releaseCapture ) {obj.releaseCapture();}};return false;}}