ieoBIN.com - The Best IEO List to Discover, Invest in 2019

Tạo một trình diễn ảnh trượt với jQuery Bài viết này hướng dẫn bạn chi tiết cách dùng thư viện jQuery để tạo một khung trưng bày ảnh đơn giản trên trang web, với sự hỗ trợ của các thư viện đồ họa người dùng. Vui lòng vào trang chi tiết để xem thêm.

Scrollable image slider  is one of the interesting features in the image gallery application. This allows us to display thumbnails in the form of slides that can be scrolled automatically or manually using the control buttons.

Figure below shows a scrollable image slider featuring four thumbnails per slide. To display thumbnails from another slide, simply by clicking the navigation buttons located on the right and left slide. Slides can also be scrolled automatically by using the  left and right arrow keyboard or using  the mouse wheel.

Scrollable image gallery

Scrollable image slider

In this tutorial, i'll use Scrollable component from jQuery Tools user interface (UI) library which is based on popular jQuery javascript framework. Current version of jQuery Tools at the time of this writing is version 1.1.2, which can be downloaded here. The library itself consists of six user interface components that can be easily combined:  Tabs, Tooltip, Overlay, Scrollable, Expose, and Flashembed.

How to Setup

  • Download Scrollable component from download page and save it as jquery.tools.min.js. You can download it with jQuery (v1.3.2)  as a single file (21.75 kb) or as a separated file (3.37 kb) if you already have jQuery.
  • Include the jquery.tools.min.js in the HEAD section of your HTML file
  • 1<script src="scripts/jquery.tools.min.js" type="text/javascript"></script>


    1<script src="scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
    2<script src="scripts/jquery.tools.min.js" type="text/javascript"></script>

Using Scrollable UI library


01<a class="prevPage left"></a>
02<div class="scrollable">
03    <div class="items">
04        <!-- 1-4 -->
10        <!-- 5-8 -->
16        <!-- 10-12 -->
21    </div>
24<a class="nextPage right"></a>

line 01:  element for left/prev  button.

line 02: root element (div) for the scrollable.

line 03: wrapper element.

line 04-20: scrollable images (will be displayed  four images per slide).

line 24: element for right/next button.

CSS Code


01.scrollable {
02    background: #ccc;
03    position: relative;
04    overflow: hidden;
05    width: 690px;
06    height:145px;
07    border:1px solid #ccc;
08    -moz-border-radius:4px;
09    -webkit-border-radius:4px;
12.scrollable .items {
13    width: 20000em;
14    position: absolute;
15    clear: both;
18.scrollable img {
19    opacity: 0.6;
20    float:left;
21    margin:15px 5px 15px 15px;
22    background-color:#fff;
23    cursor:pointer;
24    width:150px;
25    height:113px;
26    -moz-border-radius:4px;
27    -webkit-border-radius:4px;
30.scrollable .active {
31    opacity:1;
32    border:2px solid #000;
33    z-index:9999;
34    position:relative;

line 01, style for  container element, the length and width depends on image size and how many images you want displayed per slide.

line 12, style for wrapper element.

line 18,  style for images in a slide.

line 30, style for selected image.

Navigation button (prev & next)

01.scrollable { float:left; }
03a.left, a.right {
04    display: block;
05    width: 18px;
06    height: 18px;
07    float: left;
08    margin: 60px 10px;
09    cursor: pointer;
12a.right { background: url(scrollable/arrow/right.png) no-repeatclear:right; margin-right: 0px;}
13a.right:hover  { background-position:0px -18px; }
14a.right:active  { background-position:0px 0px; }
16a.left  { background: url(scrollable/arrow/left.png) no-repeatmargin-left: 0px; }
17a.left:hover  { background-position:0px -18px; }
18a.left:active  { background-position:-0px 0px; }
20a.disabled { visibility:hidden !important; }

line 01, allow next and  prev buttons placed on each side of the slide.

line 12,  set size and position of prev and next buttons.

line 16,  set background image for prev and next buttons.

Javascript Code

2    $(function()  { $("div.scrollable").scrollable({size: 4}); });

$("div.scrollable") is a jQuery selector for scrollabe container. On example above, we set four images for each slide using configuration parameter 'size'. Default value of 'size' parameter is 5. You can learn more about the API of the Scrollable component on this page.

View Live DemoDownload Example Source Code

JavaScript theo ngày

Google Safe Browsing McAfee SiteAdvisor Norton SafeWeb Dr.Web