MPBrowser.JS
[復制此代碼]CODE:
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 += '<a href="http://blog.mzoe.com/" target="_blank"><img height="90" width="120" alt="" src="'+imgInfoArr[0]+'" /></a>';
}
}
}
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 < x) {
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 < y) {
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主要的特點是無刷新,簡單易用,代碼也相當的簡單,只有幾kb的JS代碼,可以與任何的後台輕易整合,最後不臭美的說還有點好看(當然換個樣式也相當的方便)。