/** * created by administrator on 2017/3/23. */ function myevent(obj,ev,fn){ if (obj.attachevent){ obj.attachevent('on'+ev,fn); }else{ obj.addeventlistener(ev,fn,false); }; }; function getbyclass(id,sclass){ var oparent = document.getelementbyid(id); var all = oparent.getelementsbytagname('*'); var array = []; for (var i=0; i0?math.ceil(speed):math.floor(speed); if(now!=json[attr])bstop=false; if(attr=='opacity'){ obj.style.filter='alpha(opacity:'+now+speed+')'; obj.style.opacity=(now+speed)/100; }else{ obj.style[attr]=speed+now+'px'; }; } if(bstop){ clearinterval(obj.timer); if(fnend)fnend(); } }, 30); } function flexing(obj,json,fnend){ clearinterval(obj.timer); obj.timer=setinterval(function(){ var now=0; var bstop=true; for (var attr in json){ if(!obj.speed)obj.speed={}; if(!obj.speed[attr])obj.speed[attr]=0; now=parseint(getstyle(obj,attr)); if(math.abs(json[attr]-now)>1 || math.abs(obj.speed[attr])>1){ bstop=false; obj.speed[attr]+=(json[attr]-now)/5; obj.speed[attr]*=0.85; var maxspeed=65; if(math.abs(obj.speed[attr])>maxspeed){ obj.speed[attr]=obj.speed[attr]>0?maxspeed:-maxspeed; }; obj.style[attr]=now+obj.speed[attr]+'px'; }; }; if(bstop){ clearinterval(obj.timer); obj.style[attr]=json[attr]+'px'; if(fnend)fnend(); }; }, 30); } function setqq(obj,num){ if (obj.length!=num.length){ alert('\nspan的个数与qq号码的个数不符,请设置2个qq号码!\n\n[设置未成功!]'); return; }else{ for (var i=0; i点击咨询"; }; }; }; function settop(id,id2,top){ var obj = document.getelementbyid(id); var box = document.getelementbyid(id2); obj.style.top = box.style.top = top+'px'; }; function dealy(id,time){ var obj = document.getelementbyid(id); var timer = settimeout(function(){ flexing(obj,{right:0}); },time*1000); }; function click_fn(id,id2){ var obj = document.getelementbyid(id); var box = document.getelementbyid(id2); obj.onclick = function(){ running(obj,{right:-200},function(){ box.style.display = 'block'; running(box,{right:10, opacity:100}); }); }; box.onclick = function(){ timer = settimeout(function(){ running(box,{right:-220,opacity:0},function(){ box.style.display = 'none'; flexing(obj,{right:0}); }); },3000); }; }; myevent(window,'load',function(){ dealy('qq_icon',1); //1秒后显示qq图标,默认为1秒,可自行设置 settop('qq_icon','cs_online',0); //设置在线客服的高度,默认150,可自行设置 var span_q = getbyclass('cs_online','qq_num'); setqq(span_q,['1393516086','754793130']); //填写2个qq号码 click_fn('qq_icon','cs_online'); });