Set the time change of the image on the webpage

Source: Internet
Author: User

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> image effect </title>
</Head>

<Body>

<Style>
. A1 {FILTER: alpha (opacity = 100); width: 100%; height: 100%}
. A2 {FILTER: alpha (opacity = 90); width: 80%; height: 80%}
. A3 {FILTER: alpha (opacity = 80); width: 70%; height: 70%}
. A4 {FILTER: alpha (opacity = 70); width: 60%; height: 60%}
. A5 {FILTER: alpha (opacity = 60); width: 50%; height: 50%}
. A6 {FILTER: alpha (opacity = 50); width: 40%; height: 40%}
. A7 {FILTER: alpha (opacity = 40); width: 30%; height: 30%}
. A8 {FILTER: alpha (opacity = 30); width: 20%; height: 20%}
. A9 {FILTER: alpha (opacity = 20); width: 10%; height: 10%}
. A10 {FILTER: alpha (opacity = 0); width: 0; height: 0}

</Style>

<Body>
<Div id = "fu">
<Div style = "POSITION: relative; width: 100px; height: 100px" id = "banner">
<A href = "#"> </a>
<A href = "#"> </a>
<A href = "#"> </a>
<A href = "#"> </a>
<A href = "#"> </a>
<A href = "#"> </a>
<A href = "#"> </a>
<A href = "#"> </a>

</Div>

</Div>
<A href = "#" onclick = "(fu. style. display = 'None ')? Fu. style. display = 'block': fu. style. display = 'none'; "> hide or show </a>
</Body>

<Script>
Var banner = document. getElementById ("banner"); // obtain the parent container
Var img = banner. getElementsByTagName ("IMG"); // obtain the IMG in the container
Var I = 0; // mark the currently displayed IMG
DisplayFlag = true; // indicates whether the outermost container is hidden.
Function checkDisplay (obj) {// loop banner's parent element. Exit the method if any layer is hidden.
While (obj. parentNode. tagName! = "BODY "){
Obj = obj. parentNode;
If (obj. style! = Null)
If (obj. offsetWidth = 0 | obj. style. display = "none" | obj. style. visibility = "hidden "){
Var imagesss = document. getElementById ("banner"). getElementsByTagName ("IMG ");

For (var fr = 0; fr <imagesss. length; fr ++ ){
Imagesss [fr]. style. visibility = "hidden ";
}
Return displayFlag = false;
}
Else
Return displayFlag = true;
}
}
Function change (){
Img = banner. getElementsByTagName ("IMG"); // obtain the IMG in the container
C = 1; // defines the className
Var t = null; // defines the timer.
T = setInterval (function (){
CheckDisplay (banner); // you can check whether the image is hidden once before running.
If (c = 10 |! DisplayFlag) // when a loop ends or is hidden, the timer is cleared.
{
Return clearInterval (t); // exit method at the same time
}
If (c! = 9) // currently, there are only 10 styles, and the cycle ends after 9.
{
Img [I]. className = "a" + c; // define a new CLASSNAME
Img [I]. style. display = 'inline'; // define the image as the display status.
Img [I]. style. visibility = 'visible ';
Img [I]. style. left = banner. offsetWidth-img [I]. offsetWidth; // right the image
}
Else {
IMG [I]. style. Left = 0; // to hide the image, first place the image to the left
IMG [I]. classname = "A1"; // restore classname
IMG [I]. style. Display = "NONE"; // hide
IMG [I]. style. Visibility = 'den den ';
}
If (I = IMG. Length-1) {// processing when the image loops to the last one
IMG [0]. style. Left = 0;
IMG [0]. style. Display = "inline"; // control the display of 1st Images
IMG [0]. style. Visibility = 'visible ';
IMG [0]. classname = "A" + (10-c); // defines the classname of the 1st Images
}
Else {
// Otherwise, change the next image of I.
IMG [I + 1]. style. Left = 0;
IMG [I + 1]. style. Display = "inline ";
IMG [I + 1]. style. Visibility = 'visable ';
IMG [I + 1]. classname = "A" + (10-c );
}

C ++; // STYLE tag

}, 100); // 0. Change once per second
I ++;
If (I> = IMG. Length) {// loop to the last one, the I will be 0
I = 0;
}
}
Change ();
SetInterval (change, 2000); // Timer

</Script>
<! -- The image conversion effect ends -->
</Body>
</Html>

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.