Javascript + CSS for image shutter effect, javascriptcss
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"); } </script>
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;}
Test.html
<Html lang = "zh-CN" xmlns = "http://www.w3.org/1999/xhtml">
The function of switching images with arrows is only implemented using javascript and css.
The Code is as follows:
<Style type = "text/css">
# Scroll {width: 140px; height: 210px; overflow: hidden; border: 1px solid red ;}
# Scroll ul {width: 700px; height: 210px; padding: 0; margin: 0; list-style: none ;}
# Scroll ul li {width: 138px; height: 208px; float: left; border: 1px solid yellow ;}
# Scroll ul li img {width: 138px; height: 208px ;}
. Container {padding: 0 60px; width: 140px; position: relative ;}
# Left, # right {width: 50px; height: 50px; position: absolute; top: 80px; border: 1px solid blue; cursor: pointer ;}
# Left {left: 0px ;}
# Right {right: 0px ;}
</Style>
<Div class = "container">
<Div id = "left"> </div>
<Div id = "scroll">
<Ul>
<Li> </li>
<Li> </li>
<Li> </li>
<Li> </li>
<Li> </li>
</Ul>
</Div>
<Div id = "right"> </div>
</Div>
<Script type = "text/javascript">
Var endscroll, T;
Function scrol (direction, endscroll, step ){
Var obj1 = document. getElementById ("scroll ");
If (direction = "right & q ...... remaining full text>
How javascript dynamically selects css external style connections
When parsing HTML pages, the browser automatically loads css Connection Files and introduces two types of external css files. One is the link using html tags, another method is to use the import function (CSS-specific) in the <style> label)
Either way, as long as they change, the browser will automatically load the css style file to the current page and modify the page content.
Using javascript to dynamically create a link node to the page can achieve this effect, that is, the principle of the problem is displayed.