lightslider-支持移動觸摸的輕量級jQuery幻燈片插件_html/css_WEB-ITnose
Jun 24, 2016 am 11:30 AM
簡要教程
lightslider是一款輕量級的響應(yīng)式j(luò)Query幻燈片插件。lightslider幻燈片插件能夠支持移動觸摸設(shè)備,它可以制作為帶縮略圖的內(nèi)容幻燈片,或者制作為無限循環(huán)的旋轉(zhuǎn)木馬。它的特點(diǎn)還有:
- 完全響應(yīng)式設(shè)計(jì),自動適配任何設(shè)備。
- 可以單獨(dú)設(shè)置每一個breakpoint。
- 畫廊模式中可以創(chuàng)建帶縮略圖的幻燈片。
- 支持移動手機(jī)的swipe和觸摸拖拽。
- 可動態(tài)添加或刪除幻燈片。
- 文件體積小,主題豐富,實(shí)現(xiàn)簡單。
- 采用CSS過渡效果,不支持CSS過渡效果的瀏覽器中使用jQuery來回退。
- 提供豐富的回調(diào)函數(shù)和公開方法。
- 提供自動播放和無限循環(huán)的旋轉(zhuǎn)木馬模式。
- 支持鍵盤、箭頭和圓點(diǎn)導(dǎo)航。
- 跨瀏覽器、跨設(shè)備:Chrome, Safari, Firefox, Opera, IE7+, IOS, Android, windows phone。
- 同一個頁面中可以生成多個幻燈片實(shí)例。
- 幻燈片的內(nèi)容可以是圖片、視頻等。
查看演示 ???? 下載插件
安裝
可以通過npm或bower來安裝該幻燈片插件。
$ bower install lightslider$ npm install lightslider
或者下載壓縮包,在頁面中引入以下文件。
<link type="text/css" rel="stylesheet" href="css/lightslider.css" /><script src="js/jquery.min.js"></script><script src="js/lightslider.js"></script>
使用方法
HTML結(jié)構(gòu)
lightslider幻燈片的基本HTML結(jié)構(gòu)如下:
<ul id="light-slider"> <li> <h3>First Slide</h3> <p>Lorem ipsum Cupidatat quis pariatur anim.</p> </li> <li> <h3>Second Slide</h3> <p>Lorem ipsum Excepteur amet adipisicing fugiat velit nisi.</p> </li> ...</ul>
初始化插件
在頁面DOM元素加載完畢之后,可以通過lightSlider()方法來初始化該幻燈片插件。
<script type="text/javascript"> $(document).ready(function() { $("#light-slider").lightSlider(); });</script>
配置參數(shù)
該幻燈片插件可用的配置參數(shù)有:
參數(shù) | 類型 | 默認(rèn)值 | 描述 |
item | number | 3 | 同時顯示的slide的數(shù)量 |
autoWidth | boolean | false | 定制每一個slide的寬度 |
slideMove | number | 1 | 同一時間被移動的slide的數(shù)量 |
slideMargin | number | 10 | 每一個slide之間的間距 |
addClass | string | '' | 為幻燈片添加額外的class |
mode | string | 'slide' | 動畫過渡的類型,可以是'slide'或'fade' |
useCSS | boolean | true | true表示使用CSS動畫過渡效果,false表示使用jQuery動畫過渡效果 |
cssEasing | string | 'ease' | CSS過渡動畫使用的easing效果 |
easing | string | 'linear' | jQuery過渡動畫使用的easing效果 |
speed | number | 400 | 過渡動畫的持續(xù)時間,單位毫秒 |
auto | boolean | false | 如果設(shè)置為true,幻燈片將自動播放 |
pauseOnHover | boolean | false | 鼠標(biāo)滑過時停止自動播放 |
loop | boolean | false | false表示在播放到最后一幀時不會跳轉(zhuǎn)到開頭重新播放 |
slideEndAnimation | bolean | true | 允許slideEnd動畫 |
pause | number | 2000 | 兩個過渡動畫之間的間隔時間 |
keyPress | boolean | false | 是否允許使用鍵盤導(dǎo)航 |
controls | boolean | true | 如果設(shè)置為false,prev/next按鈕將不會被顯示 |
prevHtml | string | '' | 自定義prev按鈕的HTML |
nextHtml | string | '' | 自定義next按鈕的HTML |
rtl | boolean | false | 改變方向,從右到左 |
adaptiveHeight | boolean | false | 基于各個slide的高度來動態(tài)調(diào)整幻燈片的高度 |
vertical | boolean | false | 制作垂直幻燈片效果 |
verticalHeight | number | 500 | 垂直幻燈片模式中設(shè)置slide的高度(如果slide數(shù)量大于1) |
vThumbWidth | number | 100 | 垂直幻燈片模式中縮略圖的寬度 |
thumbItem | number | 10 | 同時顯示縮略圖的數(shù)量 |
pager | boolean | true | 是否開啟圓點(diǎn)導(dǎo)航 |
gallery | boolean | true | 是否開啟帶縮略圖的幻燈片模式 |
galleryMargin | number | 5 | 畫廊和slide之間的間距 |
thumbMargin | number | 3 | 縮略圖之間的間距 |
currentPagerPosition | string | 'middle' | 縮略圖的位置,可以是: 'left', 'middle', 'right' |
enableTouch | boolean | true | 是否支持移動觸摸 |
enableDrag | boolean | true | 是否支持桌面設(shè)備中使用鼠標(biāo)拖拽切換幻燈片 |
freeMove | boolean | true | 是否允許在swipe或drag的時候自由移動幻燈片 |
responsive | object | null | 單獨(dú)設(shè)置每一個breakpoint |
回調(diào)函數(shù)
回調(diào)函數(shù) | 參數(shù) | 描述 |
onBeforeStart | el | 幻燈片開始加載時觸發(fā) |
onSliderLoad | el | 幻燈片被加載后立刻執(zhí)行 |
onBeforeSlide | el | 每一個slide過渡動畫之前被執(zhí)行 |
onAfterSlide | el | 每一個slide過渡動畫之后被執(zhí)行 |
onBeforeNextSlide | el | 每一次"Next" slide過渡動畫被執(zhí)行前觸發(fā) |
onBeforePrevSlide | el | 每一次"Prev" slide過渡動畫被執(zhí)行前觸發(fā) |
公開方法

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

To use HTML button elements to achieve clickable buttons, you must first master its basic usage and common precautions. 1. Create buttons with tags and define behaviors through type attributes (such as button, submit, reset), which is submitted by default; 2. Add interactive functions through JavaScript, which can be written inline or bind event listeners through ID to improve maintenance; 3. Use CSS to customize styles, including background color, border, rounded corners and hover/active status effects to enhance user experience; 4. Pay attention to common problems: make sure that the disabled attribute is not enabled, JS events are correctly bound, layout occlusion, and use the help of developer tools to troubleshoot exceptions. Master this

Metadata in HTMLhead is crucial for SEO, social sharing, and browser behavior. 1. Set the page title and description, use and keep it concise and unique; 2. Add OpenGraph and Twitter card information to optimize social sharing effects, pay attention to the image size and use debugging tools to test; 3. Define the character set and viewport settings to ensure multi-language support is adapted to the mobile terminal; 4. Optional tags such as author copyright, robots control and canonical prevent duplicate content should also be configured reasonably.

TolearnHTMLin2025,chooseatutorialthatbalanceshands-onpracticewithmodernstandardsandintegratesCSSandJavaScriptbasics.1.Prioritizehands-onlearningwithstep-by-stepprojectslikebuildingapersonalprofileorbloglayout.2.EnsureitcoversmodernHTMLelementssuchas,

How to make HTML mail templates with good compatibility? First, you need to build a structure with tables to avoid using div flex or grid layout; secondly, all styles must be inlined and cannot rely on external CSS; then the picture should be added with alt description and use a public URL, and the buttons should be simulated with a table or td with background color; finally, you must test and adjust the details on multiple clients.

Using HTML sums allows for intuitive and semantic clarity to add caption text to images or media. 1. Used to wrap independent media content, such as pictures, videos or code blocks; 2. It is placed as its explanatory text, and can be located above or below the media; 3. They not only improve the clarity of the page structure, but also enhance accessibility and SEO effect; 4. When using it, you should pay attention to avoid abuse, and apply to content that needs to be emphasized and accompanied by description, rather than ordinary decorative pictures; 5. The alt attribute that cannot be ignored, which is different from figcaption; 6. The figcaption is flexible and can be placed at the top or bottom of the figure as needed. Using these two tags correctly helps to build semantic and easy to understand web content.

When there is no backend server, HTML form submission can still be processed through front-end technology or third-party services. Specific methods include: 1. Use JavaScript to intercept form submissions to achieve input verification and user feedback, but the data will not be persisted; 2. Use third-party serverless form services such as Formspree to collect data and provide email notification and redirection functions; 3. Use localStorage to store temporary client data, which is suitable for saving user preferences or managing single-page application status, but is not suitable for long-term storage of sensitive information.

class, id, style, data-, and title are the most commonly used global attributes in HTML. class is used to specify one or more class names to facilitate style setting and JavaScript operations; id provides unique identifiers for elements, suitable for anchor jumps and JavaScript control; style allows for inline styles to be added, suitable for temporary debugging but not recommended for large-scale use; data-properties are used to store custom data, which is convenient for front-end and back-end interaction; title is used to add mouseover prompts, but its style and behavior are limited by the browser. Reasonable selection of these attributes can improve development efficiency and user experience.

Native lazy loading is a built-in browser function that enables lazy loading of pictures by adding loading="lazy" attribute to the tag. 1. It does not require JavaScript or third-party libraries, and is used directly in HTML; 2. It is suitable for pictures that are not displayed on the first screen below the page, picture gallery scrolling add-ons and large picture resources; 3. It is not suitable for pictures with first screen or display:none; 4. When using it, a suitable placeholder should be set to avoid layout jitter; 5. It should optimize responsive image loading in combination with srcset and sizes attributes; 6. Compatibility issues need to be considered. Some old browsers do not support it. They can be used through feature detection and combined with JavaScript solutions.
