/* 创建异步方法 */ function createxhr() { if (typeof xmlhttprequest != 'undefined') { return new xmlhttprequest(); } else if (typeof activexobject != 'undefined') { var version = [ 'msxml2.xmlhttp.6.0', 'msxml2.xmlhttp.3.0', 'msxml2.xmlhttp' ]; for (var i = 0; version.length; i ++) { try { return new activexobject(version[i]); } catch (e) { //跳过 } } } else { throw new error('您的系统或浏览器不支持xhr对象!'); } } //名值对转换为字符串 function paramsjoin(data) { var arr = []; for (var i in data) { arr.push(encodeuricomponent(i) + '=' + encodeuricomponent(data[i])); } return arr.join('&'); } //封装ajax function ajax(obj) { var xhr = createxhr(); obj.url = obj.url + '/rand/' + math.random(); obj.data = paramsjoin(obj.data); if (obj.method === 'get') obj.url += obj.url.indexof('?') == -1 ? '/' + obj.data : '/' + obj.data; if (obj.async === true) { xhr.onreadystatechange = function () { if (xhr.readystate == 4) { callback(); } }; } xhr.open(obj.method, obj.url, obj.async); if (obj.method === 'post') { xhr.setrequestheader('content-type', 'application/x-www-form-urlencoded'); xhr.send(obj.data); } else { xhr.send(null); } if (obj.async === false) { callback(); } function callback() { if (xhr.status == 200) { obj.success(xhr.responsetext); } else { alert('获取数据错误!错误代号:' + xhr.status + ',错误信息:' + xhr.statustext,'error'); } } } /* js常用函数 v.0.0.3 */ function g(objname){if(document.getelementbyid){return eval('document.getelementbyid("'+objname+'")')}else{return eval('document.all.'+objname)}} //取得id的对象 function hide(a){ a = g(a); if(!a) return; a.style.display = "none"; a.style.visibility = 'hidden'; return a } function bhmovechild(a){a=g(a);if(!a) return;document.body.removechild(a);} /* 获取物理高度 */ var getheight=function(){ var f=document,a=f.body,d=f.documentelement,c=f.compatmode=="backcompat"?a:f.documentelement; return math.max(d.scrollheight,a.scrollheight,c.clientheight) }; /* 获取物理宽度 */ var getwidth=function(){ var f=document,a=f.body,d=f.documentelement,c=f.compatmode=="backcompat"?a:f.documentelement; return math.max(d.scrollwidth,a.scrollwidth,c.clientwidth) }; //影藏遮罩层 function hide(){ hide('vmask'); bhmovechild('vmask'); } /* 创建遮罩层 */ function cmask(){ thebody=document.body; v = document.createelement("div"); v.id = "vmask"; v.classname = "cscreen"; v.style.display = "block"; v.style.visibility = 'visible'; v.style.width = getwidth()+"px"; v.style.height = getheight()+"px"; thebody.appendchild(v); } /* 优化遮罩层 ps:随着屏幕的扩大或者缩小自动铺满 */ window.onresize = function(){ if(g("vmask")){ var obj = g("vmask"); obj.style.width = getwidth() + 'px'; obj.style.height = getheight() + 'px'; } } /* 滚动 */ function switch_div(wraper,prev,next,img,speed,or){ var wraper = $(wraper); var prev = $(prev); var next = $(next); var img = $(img).find('ul'); var w = img.find('li').outerwidth(true); var s = speed; next.click(function(){ img.animate({'margin-left':-w},function(){ img.find('li').eq(0).appendto(img); img.css({'margin-left':0}); }); }); prev.click(function(){ img.find('li:last').prependto(img); img.css({'margin-left':-w}); img.animate({'margin-left':0}); }); if (or == true){ ad = setinterval(function() { next.click();},s*1000); wraper.hover(function(){clearinterval(ad);},function(){ad = setinterval(function() { next.click();},s*1000);}); } }