Jquery scroll focus graph banner image, the mouse goes through the display of the top and bottom pages, suitable for the demonstration of pages with relatively large width and height, interested friends can refer to jquery scroll focus graph banner image left and right, move the mouse over the top and bottom pages
Suitable for pages with relatively large width and height
Demo
The Code is as follows:
The 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
The Code is as follows:
$ (Function (){
Var sWidth = $ ("# focus"). width ();
Var len = $ ("# focus ul li"). length;
Var index = 0;
Var picTimer;
Var btn ="
";
For (var I = 0; I <len; I ++ ){
Btn + = "";
}
Btn + ="
";
$ ("# 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 );
}
});