Use a section of JS program to realize the animation function _javascript skill

Source: Internet
Author: User
Tags prev setinterval
Since IE on the flash display way to change, flash this thing suddenly became a chicken.
Many sites have removed the previous Flash animation, instead of a JS program to achieve the animation function.

CSDN Home page is also so. I was bored and wrote one of my own, featuring the following:

1. Search Engine Friendly
2. Friendly to the art, because the data and code is separate, completely do not understand the JS can be modified with fontpage animation content

You can save the JS code as a file and then <script src= "1.js" ></script&gt, and then no need to modify the code to a letter
Animation can be implemented on multiple pages.


The code is as follows:

Copy Code code 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" ><a
href= "#" target=_blank>Id= "g_img" style= "Filter:revealtrans (duration=1,transition=23); width:266px;height:220px;border:1px Green SOLID" src= "Yun_qi_img/xian.gif" >
</a><a
href= "http://www.baidu.com/" for= "yun_qi_img/xian.gif" target= "_blank" &GT;1.CSDN programmer </a><a
href= "http://www.126.com/" for= "http://zi.csdn.net/microsoft280_187.jpg" target= "_blank" &GT;2.CSDN programmer </a> <a
href= "Yun_qi_img/live.gif" target= "_blank" &GT;3.CSDN programmer </a><a
href= "Yun_qi_img/new-mba.gif" target= "_blank" &GT;4.CSDN programmer </a><a
href= "yun_qi_img/error.html" target= "_blank" &GT;5.CSDN programmer </a>
</div>

<script language= "JavaScript" >
function f () {
var g_sec=3//After a few seconds switch pictures
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 ("A")
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.target=g_items[g_index].target

}

for (Var i=1;i<arr_length;i++) {
G_items.push ({txt:arr[i].innerhtml,
Url:arr[i].href,
Target:arr[i].target,
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.