Seamless JS image scrolling (easy to use)

Source: Internet
Author: User

After the original copy, it can be used without any changes! If you have any questions

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>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> rolling code </title>
<Style>
* {Margin: 0; padding: 0 ;}
Ul, li {list-style: none ;}
. Left_1 {width: 500px; height: 100px; margin: 0 auto ;}
. Left_1 ul {}
. Left_1 li {float: left; width: 120px; height: 100px; line-height: 100px; text-align: center ;}
. Left_1 p {width: 50px; he
100px; line-height: 100px ;}
. Left_1_ I div {width: 100px; height: 100px; line-height: 100px; border: 1px solid # e5e5e5; margin-left: 10px; padding-left: 10px ;}
</Style>
<Script language = "javascript">
Function scrollSZ (con_id, speed, direct ){
Var con, items, heightHalf, heightAll;
Var timer;
Speed = parseInt (speed); // get the set speed Parameter
Con = document. getElementById (con_id );
Con. style. overflow = "hidden ";
If (direct = "top "){
Direct = "top ";
} Else if (direct = "bottom "){
Direct = "bottom ";
} Else {
Direct = "top ";
}

Con. innerHTML + = con. innerHTML;
Con. innerHTML + = con. innerHTML;
Items = getChildNodes (con );
If (items. length <1 ){
Return;
}
HeightAll = 0;
For (var I = 0; I <items. length; I ++ ){
Var numTop, numBottom;
If (!! Window. ActiveXObject ){
NumTop = items [I]. currentStyle ["marginTop"];
NumBottom = items [I]. currentStyle ["marginBottom"];
} Else {
NumTop = document. defaultView. getComputedStyle (items [I], null) ["marginTop"];
NumBottom = document. defaultView. getComputedStyle (items [I], null) ["marginBottom"];
}
NumTop = parseInt (numTop );
NumBottom = parseInt (numBottom );
NumTop + = numBottom;
If (numTop> 0 ){
HeightAll + = numTop;
}
HeightAll + = items [I]. offsetHeight;
}
HeightHalf = heightAll/2;
If (direct = "bottom "){
Con. scrollTop = heightHalf;
Timer = setInterval (_ scrollBottom, speed );
} Else if (direct = "top "){
Timer = setInterval (_ scrollTop, speed );
}
Con. onmouseover = function (){
If (timer ){
ClearInterval (timer );
Timer = null;
}
};
Con. onmouseout = function (){
If (! Timer ){
If (direct = "top "){
Timer = setInterval (_ scrollTop, speed );
} Else if (direct = "bottom "){
Timer = setInterval (_ scrollBottom, speed );
}

}
};
Function _ scrollTop (){
If (con. scrollTop Con. scrollTop + = 2;
} Else {
Con. scrollTop = 0;
}
}
Function _ scrollBottom (){
If (con. scrollTop> 0 ){
Con. scrollTop-= 2;
} Else {
Con. scrollTop = heightHalf;
}
}
}
Function scrollSP (con_id, speed, direct ){
Var con, innerCon, timer, items, widthAll, widthHalf;
Speed = parseInt (speed );
Con = document. getElementById (con_id );
Con. style. overflow = "hidden ";
Items = getChildNodes (con );
If (items. length = 1 ){
InnerCon = items [0];
} Else {
Return;
}
InnerCon. innerHTML + = innerCon. innerHTML;
InnerCon. innerHTML + = innerCon. innerHTML;
Items = getChildNodes (innerCon );
If (items. length <1 ){
Return;
}
WidthAll = 0;
For (var I = 0; I <items. length; I ++ ){

}

For (var I = 0; I <items. length; I ++ ){
Var numLeft, numRight;
If (!! Window. ActiveXObject ){
Items [I]. style. styleFloat = "left ";
NumLeft = items [I]. currentStyle ["marginLeft"];
NumRight = items [I]. currentStyle ["marginRight"];
} Else {
Itemspolici2.16.style.css Float = "left ";
NumLeft = document. defaultView. getComputedStyle (items [I], null) ["marginLeft"];
NumRight = document. defaultView. getComputedStyle (items [I], null) ["marginRight"];
}
NumLeft = parseInt (numLeft );
NumRight = parseInt (numRight );
NumLeft + = numRight;
If (numLeft> 0 ){
WidthAll + = numLeft;
}
WidthAll + = items [I]. offsetWidth;
}
WidthHalf = widthAll/2;
InnerCon. style. width = widthAll + "px ";
If (direct = "left "){
Direct = "left ";
} Else if (direct = "right "){
Direct = "right ";
} Else {
Direct = "left"
}
If (direct = "left "){
Timer = setInterval (_ scrollLeft, speed );
} Else if (direct = "right "){
Con. scrollLeft = widthHalf;
Timer = setInterval (_ scrollRight, speed );
}
Con. onmouseover = function (){
If (timer ){
ClearInterval (timer );
Timer = null;
}
}
Con. onmouseout = function (){
If (direct = "left "){
Timer = setInterval (_ scrollLeft, speed );
} Else {
Timer = setInterval (_ scrollRight, speed );
}
}
Function _ scrollLeft (){

If (con. scrollLeft <widthHalf ){
Con. scrollLeft + = 2;
} Else {
Con. scrollLeft = 0;
}
}
Function _ scrollRight (){
If (con. scrollLeft> 0 ){
Con. scrollLeft-= 2;
} Else {
Con. scrollLeft = widthHalf;
}
}
}
Function getChildNodes (obj) {// obtain the element subnode
Var childList, list;
ChildList = new Array ();
List = obj. childNodes;
For (var I = 0; I <list. length; I ++ ){
If (list [I]. nodeType = 1)
ChildList [childList. length] = list [I];
}
Return childList;
}
</Script>
</Head>
<Body>


<Div id = "left_1" class = "left_1">
<Div class = "left_polici">
<P> 1 </p>
<P> 2 </p>
<P> 3 </p>
<P> 4 </p>
<Div> B </div>
<Div> a </div>
</Div>
</Div>
<Script language = "javascript"> scrollSP ("left_1", 10, "right"); </script>
</Body>
</Html>

 

Related Article

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.