Using JS to realize image expansion and contraction

Source: Internet
Author: User

1, the Element center amplification:

1> In addition to changing the width of the element, but also to change the positioning of the element (Left,top), if the picture is enlarged one times, then the displacement is magnified by half the width.

The 2> element must be positioned. Therefore, in the CSS set as a floating layout, you need to use JS to convert the layout, relative to the user's eye position remains unchanged

Note: When using JS to set CSS style, in the same code block, some CSS style settings have higher permissions than other styles.

<!DOCTYPE HTML><HTMLLang= "en"><Head>    <MetaCharSet= "UTF-8">    <title>Title</title>    <style>Body{margin:0;padding:0;        }Li{width:100px;Height:100px;Background-color:Red;float: Left;List-style:None;margin:10px 0 0 10px;       }#ul1{margin:0;padding:0px;width:330px;margin:100px Auto 0;position:relative;        }    </style></Head><Scriptsrc= "Startmove.js"></Script><Script>window.onload=function () {        varOul=document.getElementById ('UL1'); varALi=Oul.getelementsbytagname ('Li'); varZIndex=1;  for(varI=0; I<Ali.length;i++) {Ali[i].style.left=Ali[i].offsetleft+'px'; Ali[i].style.top=Ali[i].offsettop+'px'; Ali[i].pos={left:ali[i].offsetleft,top:ali[i].offsettop}; }         for (varI=0; I<Ali.length;i++) {ali[i].style.position='Absolute'; Ali[i].style.margin='0px'; Ali[i].onmouseover=function () {                 This. Style.backgroundcolor='Blue';  This. Style.zindex=ZIndex++; Startmove ( This, {width: $, Height: $, left: This. Pos.left- -, Top: This. Pos.top- -                }); } ali[i].onmouseout=function () {                 This. Style.backgroundcolor='Red'; Startmove ( This, {width: -, Height: -, left: This. Pos.left, Top: This. Pos.top}); }        }    }</Script><Body>    <ulID= "UL1">        <Li></Li>        <Li></Li>        <Li></Li>        <Li></Li>        <Li></Li>        <Li></Li>        <Li></Li>        <Li></Li>        <Li></Li>    </ul></Body></HTML>

Using JS to realize image expansion and contraction

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.