Javascript instance sharing-image effects with three-dimensional effects

Source: Internet
Author: User

This example is written by me once, hoping to help you and learn together. Effect:

The html code is as follows:

Copy codeThe Code is as follows:
<Html xmlns = "http://www.w3.org/1999/xhtml" xml: lang = "en" lang = "en">
<Head>
<Title> Image Browsing tool creation </title>
<Script type = "text/javascript" src = "js/main. js"> </script>
<Link rel = "stylesheet" type = "text/css" href = "style/css.css">
</Head>
<Body>
<Div id = "pic_browser">


<Div class = "mask3" onclick = "javascript: jzk. ui. moveImg (3);"> </div> <! -- Adds a three-level mask -->


<Div class = "mask2" onclick = "javascript: jzk. ui. moveImg (2);"> </div> <! -- Adds a secondary mask -->


<Div class = "mask1" onclick = "javascript: jzk. ui. moveImg (1);"> </div> <! -- Adds a level-1 mask -->


<Div class = "mask5" onclick = "javascript: jzk. ui. moveImg (-1);"> </div> <! -- Same effect as mask1 -->


<Div class = "mask6" onclick = "javascript: jzk. ui. moveImg (-2);"> </div> <! -- Same effect as mask2 -->


<Div class = "mask7" onclick = "javascript: jzk. ui. moveImg (-3);"> </div> <! -- Same effect as mask3 -->


</Div>
</Body>
</Html>

The css code is as follows:

Here mask1, 2, 3... is a div that covers several photos. The opacity attribute is used to define transparency, which can realize a sense of opacity and make the appearance more beautiful.

Copy codeThe Code is as follows:
Body {width: 1340px; height: 500px; background: url (../images/body_bg.gif) no-repeat ;}
# Pic_browser {width: 860px; height: 192px; position: relative; margin: 130px pixel ;}
# Pic_browser img {position: absolute; border: none ;}

. Prev {top: 76px; left: 0px ;}
# Img1,. mask3 {width: pixel PX; height: 70px; left: 45px; top: 61px; z-index: 4 ;}
# Img2,. mask2 {width: 166px; height: 110px; left: 95px; top: 41px; z-index: 5 ;}
# Img3,. mask1 {width: 226px; height: 150px; left: 175px; top: 21px; z-index: 6 ;}
# Img4 {width: 290px; height: 192px; left: 285px; top: 0px; z-index: 7 ;}
# Img5,. mask5 {width: 226px; height: 150px; right: 175px; top: 21px; z-index: 6 ;}
# Img6,. mask6 {width: 166px; height: 110px; right: 95px; top: 41px; z-index: 5 ;}
# Img7,. mask7 {width: pixel PX; height: 70px; right: 45px; top: 61px; z-index: 4 ;}
. Next {top: 76px; right: 0px ;}

. Mask1,. mask2,. mask3,. mask5,. mask6,. mask7 {background: # fff; position: absolute ;}
. Mask1,. mask5 {opacity: 0.3 ;}
. Mask2,. mask6 {opacity: 0.5 ;}
. Mask3,. mask7 {opacity: 0.7 ;}

The js Code is as follows:

Copy codeThe Code is as follows:
Window. onload = function ()
{
Jzk. app. initImg ();
}

Var imgArray = new Array ();
ImgArray [0] = 'images/1.jpg ';
ImgArray [1] = 'images/2.jpg ';
ImgArray [2] = 'images/3.jpg ';
ImgArray [3] = 'images/4.jpg ';
ImgArray [4] = 'images/5.jpg ';
ImgArray [5] = 'images/6.jpg ';
ImgArray [6] = 'images/7.jpg ';
Var base = 0;

Var jzk ={};/* defines the namespace */

Jzk. tools ={};/* layer first layer */

Jzk. ui ={};/* Layer 2 */
Jzk. ui. moveImg = function (offset)
{
Base = (base-offset );
For (var I = base; I <base + 7; I ++)/* defines I as the variable under the array */
{
Var img = document. getElementById ('img '+ (I-base + 1);/* Ensure that the img variable is img1, img2, img3... until the seven img elements of img7 */
If (I <0)/* array subscript I <0, indicating offset> 0 ,*/
{
Img. src = imgArray [imgArray. length + I];
}
Else if (I> imgArray. length-1)
{
Img. src = imgArray [i-imgArray.length];
}
Else
{
Img. src = imgArray [I];
}
}
}

Jzk. app ={};/* Layer 3 */
Jzk. app. initImg = function ()/* initialize the display image, that is, call the moveImg function process: parameter 7, base equals-7, I equals-7,-6,-5, -4,-3,-2,-1. The corresponding elements are img1, img2 ,... img7, so there are: img1 = imgArray [-7 + 7], img2 = imgArray [-6 + 7]... */
{
Jzk. ui. moveImg (7);/* The initial parameter should be set to the number of visible sheets (7 in this example );*/
}
It is difficult to understand the js Code of the three files. I have also provided detailed comments above. If anyone else does not understand the comments, they can be discussed in the following comments.

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.