Use a js program to implement the animation function

Source: Internet
Author: User

Since ie changed the display mode of flash, flash has suddenly become a chicken rib.
Many websites have removed the previous flash Animation and switched to a js program to implement the animation function.

The same is true for the csdn homepage .. I was bored and wrote one by myself. The features are as follows:

1. search engine friendly
2. It is friendly to artists, because the data and code are separated. if Javascript is not understood at all, you can use fontpage to modify the animation content.

You can save the js Code as a file and then <script src = "1.js"> </script>, without having to change the code to a letter.
You can achieve animation in multiple pages.

The Code is as follows:

Copy codeThe Code is as follows: <style>
# G_div {text-align: right; overflow: hidden}
. B {width: 24px; height: 16px; background: #737373; font-size: 14px; font-weight: bold; color: # fff; text-decoration: none; margin-left: 1px}
. B: hover {width: 24px; height: 16px; background: #780001; font-size: 14px; font-weight: bold; color: # fff; text-decoration: none; margin-left: 1px}
. Bhover {width: 24px; height: 16px; background: #780001; font-size: 14px; font-weight: bold; color: # fff; text-decoration: none; margin-left: 1px}
</Style>

<Div id = "g_div" style = "width: 270px; height: 252px"> <
Href = "#" target = _ blank> Id = "g_img" style = "FILTER: revealTrans (duration = 1, transition = 23); width: 266px; height: 220px; border: 1px green solid "src =" http://zi.csdn.net/xian.gif ">
</A> <
Href = "http://www.baidu.com/" for = "http://zi.csdn.net/xian.gif" target = "_ blank"> 1. CSDN programmer </a> <
Href = "http://www.126.com/" for = "http://zi.csdn.net/microsoft280_187.jpg" target = "_ blank"> 2. CSDN programmer </a> <
Href = "http://mp3.baidu.com/" for = "http://zi.csdn.net/live.gif" target = "_ blank"> 3. CSDN programmer </a> <
Href = "http://post.baidu.com/" for = "http://zi.csdn.net/new-mba.gif" target = "_ blank"> 4. CSDN programmer </a> <
Href = "http://top.baidu.com/" for = "http://zi.csdn.net/book.jpg" target = "_ blank"> 5. CSDN programmer </a>
</Div>

<Script language = "JavaScript">
Function f (){
Var g_sec = 3 // seconds before switching the image
Var g_items = new Array ()
Var g_div = document. getElementById ("g_div ")
Var g_img = document. getElementById ("g_img ")
Var g_imglink = g_img.parentElement
Var arr = g_div.getElementsByTagName ("")
Var arr_length = arr. length
Var g_index = 1

Var show_img = function (n ){
If (/\ d +/. test (n )){
Var prev = g_index + 1
G_index = n-1
} Else {
Var prev = (g_index> arr. length )? Arr_length-1: g_index + 1
G_index = (g_index <arr_length-2 )? (++ G_index): 0
}
If (document. all ){
G_img.filters.revealTrans.Transition = 23;
G_img.filters.revealTrans.apply ();
G_img.filters.revealTrans.play ();
}
Arr [prev]. className = "B"
Arr [g_index + 1]. className = "bhover"
G_img.src = g_items [g_index]. img. src
G_img.title+g_items+g_index+.txt
G_imglink.href = g_items [g_index]. url
G_imglink.target1_g_items1_g_index#.tar get

}

For (var I = 1; I <arr_length; I ++ ){
G_items.push ({txt: arr [I]. innerHTML,
Url: arr [I]. href,
Target: arrpolici2.16.tar get,
Img :( function () {var o = new Image; o. src = arr [I]. getAttribute ("for"); return o })()})
Arr [I]. title = arr [I]. innerHTML
Arr [I]. innerHTML = [I, ""]. join ("")
Arr [I]. className = "B"
Arr [I]. onclick = function (){
Event. returnValue = false;
Show_img (event. srcElement. innerText)
}
}
Show_img (1)
Var t = window. setInterval (show_img, g_sec * 1000)
G_img.onmouseover = function () {window. clearInterval (t )}
G_img.onmouseout = function () {t = window. setInterval (show_img, g_sec * 1000 )}
}

Window. attachEvent ("onload", f)
</Script>

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.