Jquery left and right scroll focus graph banner image, move the cursor over the display top and bottom pages
Suitable for pages with relatively large width and height
Demo
Copy codeThe Code is as follows:
<Div class = "bannerbox">
<Div id = "focus">
<Ul>
<Li> <a href = "http://www.freejs.net/" target = "_ blank">
</a> </li>
<Li> <a href = "http://www.freejs.net/" target = "_ blank">
</a> </li>
<Li> <a href = "http://www.freejs.net/" target = "_ blank">
</a> </li>
<Li> <a href = "http://www.freejs.net/" target = "_ blank">
</a> </li>
</Ul>
</Div>
</Div>
Copy codeThe Code is as follows:
@ Charset "UTF-8 ";
Img {border: 0px ;}
. Bannerbox {width: 320px; height: 150px; overflow: hidden; margin: 0px auto ;}
# Focus {width: 320px; height: 150px; clear: both; overflow: hidden; position: relative; float: left ;}
# Focus ul {width: 320px; height: 150px; float: left; position: absolute; clear: both; padding: 0px; margin: 0px ;}
# Focus ul li {float: left; width: 320px; height: 150px; overflow: hidden; position: relative; padding: 0px; margin: 0px ;}
# Focus. preNext {width: 250px; height: 150px; position: absolute; top: 0px; cursor: pointer ;}
# Focus. pre {left: 0; background: url (../images/sprite.png) no-repeat left center ;}
# Focus. next {rightright: 0; background: url (../images/sprite1.png) no-repeat rightright center ;}
Js files
Copy codeThe Code is as follows:
$ (Function (){
Var sWidth = $ ("# focus"). width ();
Var len = $ ("# focus ul li"). length;
Var index = 0;
Var picTimer;
Var btn = "<div class = 'btnbg '> </div> <div class = 'btn'> ";
For (var I = 0; I <len; I ++ ){
Btn + = "<span> </span> ";
}
Btn + = "</div> <div class = 'prenext pre'> </div> <div class = 'prenext next'> </div> ";
$ ("# Focus"). append (btn );
$ ("# Focus. btnBg" 2.16.css ("opacity", 0 );
$ ("# Focus. btn span" example .css ("opacity", 0.4). mouseenter (function (){
Index = $ ("# focus. btn span"). index (this );
ShowPics (index );
}). Eq (0). trigger ("mouseenter ");
$ ("# Focus. preNext" detail .css ("opacity", 0.0). hover (function (){
$ (This). stop (true, false). animate ({"opacity": "0.5"}, 300 );
}, Function (){
$ (This). stop (true, false). animate ({"opacity": "0"}, 300 );
});
$ ("# Focus. pre"). click (function (){
Index-= 1;
If (index =-1) {index = len-1 ;}
ShowPics (index );
});
$ ("# Focus. next"). click (function (){
Index + = 1;
If (index = len) {index = 0 ;}
ShowPics (index );
});
$ ("# Focus ul" ).css ("width", sWidth * (len ));
$ ("# Focus"). hover (function (){
ClearInterval (picTimer );
}, Function (){
PicTimer = setInterval (function (){
ShowPics (index );
Index ++;
If (index = len) {index = 0 ;}
},2800 );
}). Trigger ("mouseleave ");
Function showPics (index ){
Var nowLeft =-index * sWidth;
$ ("# Focus ul"). stop (true, false). animate ({"left": nowLeft}, 300 );
$ ("# Focus. btn span "). stop (true, false ). animate ({"opacity": "0.4"}, 300 ). eq (index ). stop (true, false ). animate ({"opacity": "1"}, 300 );
}
});