Js enables switching between image slides that can be called multiple times on the same page. js slides
The example in this article describes how js achieves switching between image slides that can be called multiple times on the same page. Share it with you for your reference. The specific implementation method is as follows:
Copy codeThe Code is as follows: <! 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>
<Title> Effect of switching between image slides that can be called multiple times on the same page of js </title>
<Meta http-equiv = "content-type" content = "text/html; charset = gb2312">
<! -- Add the following code between <Script language = "javascript">
// Declare the namespace
Var $ o = new Object ();
// Basic Method
$ O. base = {
E: function (a, f ){
For (var I = 0, j = a. length; I <j; I ++) {f. call (a [I], I );}
}
}
$ O. slide = function (id, arg ){
Var arg = arg | | {},
T = document. getElementById (id ),
A = t. getElementsByTagName (""),
Lis = [],
Cl = arg. color | '# f30 ',
Ctm = arg. time X 1000 | 2000,
W = t. clientWidth,
H = t. clientHeight,
B = ['<ul style = "margin: 0; padding: 0; list-style: none; display: block; position: absolute; bottom: 10px; right: 10px; "> '],
Index = 0,
$ = Null,
$ = Null;
Function change (I ){
If (!! $) {ClearTimeout ($ );}
Index =! IsNaN (I )? I: index + 1;
If (index> = a. length) {index = 0 ;}
$ O. base. e (lis, function (k) {if (k = index) {c (1, this);} else {c (0, this )}});
Var to =-index * h;
If (a [0]. offsetTop = ){
Return;
} Else {
If (!! $) {ClearInterval ($ );}
$ = SetInterval (function (){
Var ot = a [0]. offsetTop;
V = Math [to <ot? 'Floor ': 'ceil'] (to-ot) * 0.2 );
If (ot = to) {clearInterval ($) ;$ = null; st ();}
Ot + = v;
A [0]. style. marginTop = ot + "px ";
}, 30)
};
}
Function c (B, o ){
O. style. backgroundColor = !! B? Cl: "# fff ";
O. style. color = !! B? "# Fff": cl;
}
Function st (){
If (!! $) ClearTimeout ($ );
$ = SetTimeout (function () {change ()}, ctm );
}
With (t. style) {overflow = 'den den '; position = 'relative ';}
$ O. base. e (a, function (n ){
This. style. display = "block ";
With (this. firstChild. style) {borderWidth = '0'; width = w + 'px'; height = h + 'px ';}
B. push ('<li style = "width: 20px; height: 20px; line-height: 20px; display: block; float: left; margin-left: 5px; border: 1px solid '+ cl +'; background-color: # fff; color: '+ cl +'; font-size: 14px; text-align: center; cursor: pointer; "> '+ (n + 1) +' </li> ');
});
B. push ('</ul> ');
T. innerHTML + = B. join ("");
Lis = t. getElementsByTagName ("li ");
$ O. base. e (lis, function (n ){
If (n = index) {c (1, this )}
This. onmouseover = function (){
If (n! = Index) change (n );
}
});
St ();
}
</Script>
</Head>
<Body>
<! -- Add the following code to the <body> and </body> -->
<Div id = "aa" style = "width: 402px; height: 228px;">
<A href = "javascript: alert ('1')"> </a>
<A href = "javascript: alert ('2')"> </a>
<A href = "javascript: alert ('3')"> </a>
<A href = "javascript: alert ('4')"> </a>
<A href = "javascript: alert ('5')"> </a>
<A href = "javascript: alert ('6')"> </a>
<A href = "javascript: alert ('7')"> </a>
<A href = "javascript: alert ('8')"> </a>
<A href = "javascript: alert ('9')"> </a>
</Div>
<Script language = "javascript">
New $ o. slide ("aa ");
</Script>
<Br>
<Div id = "bb" style = "width: 402px; height: 228px;">
<A href = "###"> </a>
<A href = "###"> </a>
<A href = "###"> </a>
<A href = "###"> </a>
<A href = "###"> </a>
</Div>
<Script language = "javascript">
New $ o. slide ("bb", {color: '# 000', time: 0.2 });
</Script>
<Br>
<Div id = "cc" style = "width: 402px; height: 228px;">
<A href = "###"> </a>
<A href = "###"> </a>
<A href = "###"> </a>
<A href = "###"> </a>
<A href = "###"> </a>
</Div>
<Script language = "javascript">
New $ o. slide ("cc", {color: 'green '});
</Script>
</Body>
</Html>
I hope this article will help you design javascript programs.