// JavaScript Document
/*
*@date 2011 10 24
*@ author tugenhua
*@ email tugenhua@126.com
*@ can be one page Multiple references
Dependent structure*/
/*How to refer to the page
new tabSlider("#tab1",4);
#tab1 is the external ID, 4 refers to the total number li
*/
function tabSlider(obj,count){
var _this = this;
_this.obj = obj;
_this.count = count;
_this.time = 2000; //Stay time
_this.n = 0;
var t;
this.slider = function(){
_this.n = 0;
var t; " .menu li").index(this);
.n = index; ){t=setInterval(_this.autoplay,_this.time)}); 1)? 0 : _this.n;
(){
this.slider();
this.addhover();
t = setInterval(this.autoplay,_this.time);
}
this.factory ();
}
Let me talk about my idea of encapsulating this js, because the idea is the most important when writing any program. As long as you can think clearly, the code will definitely be implemented! To put it more nicely, the idea is what we often call “algorithm”!
1 function tabSlider(obj,count){} Use this js to encapsulate and pass in the parameters! When on an HTML page, just call tabSlider(obj, count) directly!
2 Initialize some parameters and then customize a function this.slider = function(){} for this function. Bind a mouseover event. When initializing the first li, check whether the current div content points to the same pointer as the current li. If the same piece of content is displayed! Others are hidden!
3 Customize this.addHover event to fire this event when the mouse moves over!
4 Custom autoplay event this.autoplay = function(){} This uses the trigger method _this.n = _this.n >=(_this.count-1)? 0 : _this.n ;
$(_this.obj " .menu li").eq(_this.n).trigger("mouseover");
5 Finally, use a function to render the above function and call the above function
this.factory = function(){
this.slider( );
this.adhover();
t = setInterval(this.autoplay,_this.time);
}
this.factory();