JQuery implements the focus chart plug-in for switching image groups.

Source: Internet
Author: User

JQuery implements the focus chart plug-in for switching image groups.

This is a jQuery-based focus chart plug-in for switching images. This jQuery focus chart plug-in features that images can be switched in groups, that is, multiple images can be switched at a time, compared with other focus chart plug-ins, it can save more space and show more images to users, which is very practical.

Implementation code.

Html code:

Copy codeThe Code is as follows:
<Div class = "device">
<H2>
<A href = "javascript:;" class = "pre"> previous group </a> <a href = "javascript :; "class =" next "> next group </a> <Div class = "scroll">
<Ul>
<Li> <a href = "#">
</a> <a href =" # "class =" link "> HTML5 resource tutorial </a> </li>
<Li> <a href = "#">
</a> <a href =" # "class =" link "> HTML5 resource tutorial </a> </li>
<Li> <a href = "#">
</a> <a href =" # "class =" link "> HTML5 resource tutorial </a> </li>
<Li> <a href = "#">
</a> <a href =" # "class =" link "> HTML5 resource tutorial </a> </li>
<Li> <a href = "#">
</a> <a href =" # "class =" link "> HTML5 resource tutorial </a> </li>
<Li> <a href = "#">
</a> <a href =" # "class =" link "> HTML5 resource tutorial </a> </li>
<Li> <a href = "#">
</a> <a href =" # "class =" link "> HTML5 resource tutorial </a> </li>
<Li> <a href = "#">
</a> <a href =" # "class =" link "> HTML5 resource tutorial </a> </li>
<Li> <a href = "#">
</a> <a href =" # "class =" link "> HTML5 resource tutorial </a> </li>
<Li> <a href = "#">
</a> <a href =" # "class =" link "> HTML5 resource tutorial </a> </li>
<Li> <a href = "#">
</a> <a href =" # "class =" link "> HTML5 resource tutorial </a> </li>
<Li> <a href = "#">
</a> <a href =" # "class =" link "> HTML5 resource tutorial </a> </li>
<Li> <a href = "#">
</a> <a href =" # "class =" link "> HTML5 resource tutorial </a> </li>
<Li> <a href = "#">
</a> <a href =" # "class =" link "> HTML5 resource tutorial </a> </li>
<Li> <a href = "#">
</a> <a href =" # "class =" link "> HTML5 resource tutorial </a> </li>
<Li> <a href = "#">
</a> <a href =" # "class =" link "> HTML5 resource tutorial </a> </li>
<Li> <a href = "#">
</a> <a href =" # "class =" link "> HTML5 resource tutorial </a> </li>
<Li> <a href = "#">
</a> <a href =" # "class =" link "> HTML5 resource tutorial </a> </li>
<Li> <a href = "#">
</a> <a href =" # "class =" link "> HTML5 resource tutorial </a> </li>
<Li> <a href = "#">
</a> <a href =" # "class =" link "> HTML5 resource tutorial </a> </li>
</Ul>
</Div>
</Div>

Js Code:

Copy codeThe Code is as follows:
$ (Function (){
Var $ number = Math. ceil ($ ('. scroll ul li'). length/4); // obtain the number of scrolling screens
Var margin = 10; // sets the image spacing.
Var $ w = $ ('. scroll li'). width () + margin; // The width of a screen image
Var $ width = $ w * $ number * 2; // you can specify the ul width.
Var pre = $ ('. device. pre ');
Var next = $ ('. device. next ');
If ($ number = 1) {pre. hide (); next. hide ();}
$ ('. Scroll ul'). width ($ width );
Var num = 0;
Function autoscroll (){
Num ++;
If ($ number = 1) {return false}
If (num = $ number ){
Num = 0;
}
Var distance =-2 * $ w * num;
$ ('. Scroll ul'). stop (). animate ({left: distance });
}
Var scrollChange = setInterval (autoscscroll, 8000 );
// Hover the mouse over and pause the scroll.
$ (". Scroll ul,. pre,. next"). mouseover (function (){
$ ('. Scroll ul'). stop ()
ClearInterval (scrollChange );
});
// Move the mouse to continue scrolling
$ ('. Scroll ul,. pre,. next'). mouseout (function (){
ScrollChange = setInterval (autoscscroll, 8000 );
});
// Next group
Next. click (function (){
Num ++;
If (num >=$ number) {num = 0}
Var leftdis =-2 * $ w * num;
$ ('. Scroll ul'). stop (). animate ({left: leftdis });
});
// Previous Group
Pre. click (function (){
Num --;
If (num <0) {num = $ number-1}
Var rightdis =-2 * $ w * num;
$ ('. Scroll ul'). stop (). animate ({left: rightdis });
});
});

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.