JavaScript implementation small box to browse large image effects

Source: Internet
Author: User
Tags tostring
javascript| Special Effects

Today in playing Google Earth 4.0b, found that Print screen down the picture is very large, if directly on the Web page, because the size is too large and inappropriate, and do not want to compress the size of the picture, and then thought of this method, did not expect to achieve more easily than expected. This piece of code is also compatible with Firefox.
Limits the range of scrolling and does not appear in the background.
With the OnMouseMove event, the picture moves in real time with the mouse.

Run Code Box

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "><ptml xmlns=" http://www.w3.org/1999/xhtml "><pead><meta http-equiv=" Content-type "content=" text/html; charset=gb2312 "/><title> Untitled document </title><style type=" Text/css "><!--#pic {width:420px;height : 300px;border:3px solid #ccc; Background-image:url (01.jpg); background-repeat:no-repeat;background-position:0px 0px ; cursor:move;} --></style><script type= "Text/javascript" ><!--var p = new Array (); var speed = 0.05; Speed var picwidth = 1280; Large graph wide High var picheight = 971;var x,y//mouse pointer down background coordinates var x_new,y_new//Displacement var Haveclick = false;function Getmouseposition (eve NT) {if (document.all) {x = Document.body.scrollleft+event.clientx;y = Document.body.scrolltop+event.clienty;} else{x = Event.layerx;y = Event.layery;} Haveclick = true;} function Movestop () {Haveclick = false;} function MoveStart (event) {if (Haveclick) {if (Document.getelEmentbyid (' pic '). style.backgroundposition.length==0) {document.getElementById (' pic '). style.backgroundposition= " 0px 0px ";} p = document.getElementById (' pic '). Style.backgroundPosition.split ("") if (document.all) {x_new = Document.body.scrollleft+event.clientx;y_new = Document.body.scrolltop+event.clienty;} else{x_new = Event.layerx;y_new = Event.layery;} x2 = (speed* (x_new-x) +parseint (p[0)). toString (10); Calculated displacement y2 = (speed* (y_new-y) +parseint (p[1)). ToString (a); if (x2<-picwidth+420) x2=-picwidth+420;if (y2>0) y2= 0;if (x2>0) x2=0;if (y2<-picheight+300) Y2=-picheight+300;document.getelementbyid (' pic '). style.backgroundposition=x2+ "px" +y2+ "px";} --></script></pead><body><div id= "pic" onmousemove= "MoveStart (event)" > </div> </body></ptml>

[Ctrl + A ALL SELECT hint: You can modify some of the code, and then run]



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.