什么是MPBrowser简易图片浏览器 v1.0
来源:爱站网时间:2021-08-12编辑:网友分享
什么是MPBrowser简易图片浏览器 v1.0,爱站技术小编被前几天朋友的一句问话问的不知道怎么回答,对于这个问题,口头上真的很难表达。于是小编整理出了一份详细的介绍资料。大家来看吧
MPBrowser.js
var thisImgNo = 290;
function ajaxConn(){
var xmlhttp = false;
try{xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");}
catch(e){try{xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}
catch(e){try{xmlhttp = new XMLHttpRequest();}
catch(e){alert(e);xmlhttp = false;}}}
if(!xmlhttp)return null;
this.connect = function(Url,Method,postContent){
if(!xmlhttp)return false;
Method = Method.toUpperCase();
try{
if (Method == "GET"){
xmlhttp.open(Method,Url + '?' + postContent,true);
xmlhttp.setRequestHeader("Content-Type","text/html;charset=GB2312");
sVars = null;
}else{
xmlhttp.open(Method,Url,true);
xmlhttp.setRequestHeader("Method","POST "+Url+" HTTP/1.1");
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
}
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4){
if(xmlhttp.status == 200){
imgInfo = xmlhttp.ResponseText;
var imgInfoArr = imgInfo.split("|");
var tmpimg = new Image();
tmpimg.src = imgInfoArr[0];
thisImgNo = imgInfoArr[1];
var element = document.getElementById("img");
if(!element.xpos)element.xpos = 0;
element.style.width = (element.clientWidth + 130) + "px";
slideElement("img",element.xpos-130,0,10);
element.innerHTML += '';
}
}
}
xmlhttp.send(postContent);
}catch(z){return false;}
return true;
}
return this;
}
function loadImg(type){
var element = document.getElementById("img");
if(!element.xpos)element.xpos = 0;
if(type=="pre"){
if(element.xpos==0)return false;
slideElement("img",element.xpos+130,0,10);
}else{
if(element.xpos==-(element.clientWidth - 260)){
var myConn = new ajaxConn();
if(!myConn)return false;
myConn.connect("Cmd.asp","get","d="+thisImgNo);
}else{
slideElement("img",element.xpos-130,0,10);
}
}
}
function slideElement(elementId,x,y,inc){
var element = document.getElementById(elementId);
if(element.sliding)clearTimeout(element.sliding);
if(!element.xpos)element.xpos = 0;
if(!element.ypos)element.ypos = 0;
if(element.xpos == x && element.ypos == y) return true;
if(element.xpos > x){
var dist = Math.ceil((element.xpos-x)/inc);
element.xpos = element.xpos - dist;
}
if(element.xpos var dist = Math.ceil((x-element.xpos)/inc);
element.xpos = element.xpos + dist;
}
if(element.ypos > y) {
var dist = Math.ceil((element.ypos-y)/inc);
element.ypos = element.ypos - dist;
}
if(element.ypos var dist = Math.ceil((y-element.ypos)/inc);
element.ypos = element.ypos + dist;
}
element.style.left = element.xpos+'px';
element.style.top = element.ypos+'px';
element.sliding = setTimeout('slideElement("'+elementId+'",'+x+','+y+','+inc+')',10);
}
以上内容就是爱站技术频道小编为大家分享的什么是MPBrowser简易图片浏览器 v1.0,小编觉得MPBrowser主要的特点是无刷新,简单易用,代码也相当的简单,只有几kb的js代码,可以与任何的后台轻易整合,最后不臭美的说还有点好看(当然换个样式也相当的方便)。