The effect of the magnifying glass JS

Source: Internet
Author: User

HTML code:

Div.box>div#left+div#buttom+div#right

Div#left>img

Div#buttom>div.small>img

CSS code:

. Box{position:relative; }#left{width:310px;Height:310px;Border:1px solid Blueviolet; }#buttom{width:310px;Height:40px;Margin-top:10px; }#buttom. Small{Border:1px solid Wheat;float: Left;Margin-right:5px; }#right{width:400px;Height:310px;; Position:Absolute;Top:0; Left:320px;Border:1px solid #ccc;Display:None;Overflow:Hidden; }#right img{position:Absolute;Top:0; Left:0; }

JS Code:

1<script>2         function$ (ID) {3             returndocument.getElementById (ID);4         }5Window.onload =function () {6             varLeft = $ (' Left ');7             varButton = $ (' buttom ');8             varright = $ (' Right ');9Button.onmouseover =function(e) {Ten                 varE = e| | window.event;//Compatible Events One                 varImgobj = e.srcelement| | E.target;//Get target event source, ie under Srcelement, Firefox under Target A                 if(Imgobj.nodename = = ' IMG ') {//When the target event source is a picture - //alert (IMGOBJ.SRC); -                     varnames = IMGOBJ.SRC;//get the picture path the Console.log (names); -Console.log (Names.lastindexof ('/'));//obtained/the corner mark position -Console.log (names.substring (Names.lastindexof ('/')));//starting from the corner mark to the last picture name -                     varImgoldname = names.substring (Names.lastindexof ('/'))); +                     varImgnewname = Imgoldname.replace (' 1 ', ' 2 ');//change path from renaming - Console.log (imgnewname); +left.innerhtml = '  '; A                 } at             }; -             //The right picture shows the logic -Left.onmouseover =function () { -Right.style.display = ' block '; -                 varleftimg = Left.getelementsbytagname (' img ') [0]; -                 varNames =leftimg.src; in                 varImgoldname = names.substring (Names.lastindexof ('/'))); -                 varImgnewname = Imgoldname.replace (' 2 ', ' 3 '); toright.innerhtml = "; +                 varrightimg = Right.getelementsbytagname (' img ') [0]; -                 //Add a Move event the                  This. onmousemove =function(e) { *                     varE = e| |window.event; $                     varL = e.offsetx| | E.layerx;//compatible notation relative to the location of the event sourcePanax Notoginseng                     varr = e.offsety| |E.layery; -                     //position Large map coordinates according to proportions theRightImg.style.left = l/left.offsetwidth* (right.offsetwidth-rightimg.offsetwidth) + "px"; +RightImg.style.top = r/left.offsetheight* (right.offsetheight-rightimg.offsetheight) + "px"; A                 } the             } +             //Leave event -Left.onmouseout =function () { $Right.style.display = ' None '; $             } -         } -</script>

The effect of the magnifying glass JS

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.