Javascript+css to realize the effect of image rolling and the Code _javascript skill

Source: Internet
Author: User

The guys of ArcGIS has a profound memory for the effect of a shutter in ArcMap, want to move it to their own webgis system, holding the same idea, I also to this relatively dazzling shutter effect did a bit of research, Roar, came out, to everyone report the results

See this effect, you are not chicken moved a bit, hey, don't worry, listen to me slowly way.

First, the container. Use two div to display images of two different periods, respectively. Next, set the style of two containers, code:

#after { 
position:absolute; 
top:0px; 
left:0px; 
Background-image:url (.. /images/24.jpg); 
width:940px; 
height:529px; 
background-repeat:no-repeat; 
} 
#before { 
position:absolute; 
top:0px; 
left:0px; 
border-right:3px solid #f00; 
Background-image:url (.. /images/23.jpg); 
width:433px; 
height:529px; 
Background-repeat:no-repeat; 
max-width:940px; 
} 


This way, the picture is displayed on the web.


Next to achieve the effect of the shutter. To achieve the shutter, the most important thing is to set the width of the before, how to set it, is to get the location of the mouse, the code is as follows:

function Rollimage (evt) { 
var X=evt.pagex; 
Console.log (x); 
$ ("#before"). CSS ("width", x+ "px"); 
/script>

In this way, the effect of the shutter is achieved. The source code is as follows:

Style.css

. beforeafter{ 
width:940px; 
height:529px; 
} 
#after { 
position:absolute; 
top:0px; 
left:0px; 
Background-image:url (.. /images/24.jpg); 
width:940px; 
height:529px; 
background-repeat:no-repeat; 
} 
#before { 
position:absolute; 
top:0px; 
left:0px; 
border-right:3px solid #f00; 
Background-image:url (.. /images/23.jpg); 
width:433px; 
height:529px; 
Background-repeat:no-repeat; 
max-width:940px; 
} 

Test.html


  
 
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.