Javascript + CSS for image shutter Effect
Those who have used Arcgis will surely have a deep memory of a roller shutter In Arcmap. They want to move it to their WebGIS system and share the same idea, I have also made a research on this kind of dazzling shutter effect. I have come out and will report the results to you. Let's take a look at the figure:
Shutter Effect
If you see this effect, do you have a chicken? hey, don't worry. Listen to me.
First, container. Use two divs to display images of different periods. Next, set the style of the two containers. The Code is as follows:
#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;}
In this way, the image is displayed on the web.
Next, implement the shutter effect. To implement shutter, the most important thing is to set the before width. How to set it is to get the mouse position, the Code is as follows:
function RollImage(evt){ var x=evt.pageX; console.log(x); $(#before).css(width,x+px); }
In this way, the shutter effect 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;}
<Script src = ../jquery-1.8.3.js type = text/javascript charset = UTF-8> </script> <script type = text/javascript> function RollImage (evt ){
Var x = evt. pageX; rows (describeforeapps.css (width, x + px );} </Script>