Javascript + CSS Implementation of image shutter effects ideas and code, javascriptcss

Source: Internet
Author: User

Javascript + CSS Implementation of image shutter effects ideas and code, 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 some research on this kind of dazzling 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"> 

Use javascript to implement the menu effect code

Can this be implemented directly with css? Why do you need to use js?
Do you want to click to display the sub-menu effect? Paste all the menus. I will give you

How to hide and display JAVASCRIPT and CSS

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "www.w3.org/..al.dtd">
<Html xmlns = "www.w3.org/5o/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> untitled document </title>
</Head>

<Body>
<Script language = "JavaScript">
<! --
Function show (obj ){
Obj. style. display = obj. style. display = "none "? "": "None ";
}
// -->
</SCRIPT>
<A href = "javascript:" onclick = "show (document. getElementById ('asd ')"> click me </a>
<Div id = "asd" style = "display: none"> I'm out, I'm leaving </div>
</Body>
</Html>

Test it and use it. Remember to add points.

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.