MPBrowser simple image browser v1.0

Source: Internet
Author: User

MPBrowser. js
Copy codeThe Code is as follows:
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 );
Element. innerHTML + = '<a href = "http://blog.mzoe.com/" target = "_ blank"> </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 );
}
}
}
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 );
}

The main features of MPBrowser are no refreshing, easy to use, and simple code. Only a few kb of js code can be easily integrated with any background, in the end, the beauty is pretty nice (of course, it is quite convenient to change the style ).

Demo address: http://www.mzoe.com/demo/MPBrowser/

: Http://www.mzoe.com/downfile/MPBrowser_v1.rar

My favorite friend is D.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.