HTML code:
Copy codeThe Code is as follows:
<! DOCTYPE html>
<Html>
<Head>
<Title> </title>
<Style>
* {Padding: 0; margin: 0}
Ul {list-style: none}
. Slider-focus {width: 670px; height: 240px; overflow: hidden; position: relative; margin: 100px auto}
. Slider-focus. slider {width: 3500px; position: absolute; left: 0px; top: 0px; height: 240px}
. Slider-focus. slider li {float: left ;}
. Slider-focus. btns {position: absolute; right: 0px; bottom: 5px}
. Slider-focus. btns li {width: 18px; height: 18px; float: left; background: # fff; margin-right: 5px; cursor: pointer}
. Slider-focus. btns li. cur {background: # f60}
</Style>
</Head>
<Body>
<Div class = "slider-focus">
<Ul class = "slider">
<Li> </li>
<Li> </li>
<Li> </li>
<Li> </li>
<Li> </li>
</Ul>
<Ul class = "btns">
<Li class = "cur"> </li>
<Li> </li>
<Li> </li>
<Li> </li>
<Li> </li>
</Ul>
</Div>
<Script src = "jquery-1.9.1.js"> </script>
<Script src = "slider. js"> </script>
</Body>
</Html>
Pipeline script code:
Copy codeThe Code is as follows:
Function Sliderfocus (options ){
This. focus = options. focus;
This. slider = options. slider;
This. btns = options. btns;
This. width = options. width;
This. speed = options. speed | 800;
This. curIndex = options. curIndex | 0;
This. size = this. btns. size ();
This. init ();
This. timeout = null;
This. stopTemp = 1;
}
Sliderfocus. prototype = {
Init: function (){
This. auto ();
This. bind ();
},
Play: function (){
This. slider. stop (). animate ({
Left:-this. curIndex * this. width
}, This. speed );
},
Auto: function (){
Var that = this;
This. timeout = setTimeout (function (){
If (that. stopTemp = 0 ){
Return;
} Else {
That. next ();
That. auto ();
}
},4000 );
},
Prev: function (){
This. curIndex = -- this. curIndex <0? This. size-1: this. curIndex;
This. play ();
},
Next: function (){
This. curIndex = ++ this. curIndex> this. size-1? 0: this. curIndex;
Console. log (this. curIndex)
This. play ();
},
Stop: function (){
This. stopTemp = 0;
},
Bind: function (){
Var that = this;
This. focus. bind ("mouseover", function (){
That. stop ();
}). Bind ("mouseout", function (){
That. stopTemp = 1;
// That. auto ();
});
This. letsgo ();
},
Letsgo: function (){
Var that = this;
This. btns. bind ("click", function (){
Var index = $ (this). index ();
That. curIndex = index;
That. play ();
});
}
};
New Sliderfocus ({
Focus: $ (". slider-focus "),
Slider: $ (". slider-focus. slider "),
Btns: $ (". btns li "),
Width: 670
});