Table of Contents
First Slide
Second Slide
Home Web Front-end HTML Tutorial lightslider-支持移动触摸的轻量级jQuery幻灯片插件_html/css_WEB-ITnose

lightslider-支持移动触摸的轻量级jQuery幻灯片插件_html/css_WEB-ITnose

Jun 24, 2016 am 11:30 AM

简要教程

lightslider是一款轻量级的响应式jQuery幻灯片插件。lightslider幻灯片插件能够支持移动触摸设备,它可以制作为带缩略图的内容幻灯片,或者制作为无限循环的旋转木马。它的特点还有:

  • 完全响应式设计,自动适配任何设备。
  • 可以单独设置每一个breakpoint。
  • 画廊模式中可以创建带缩略图的幻灯片。
  • 支持移动手机的swipe和触摸拖拽。
  • 可动态添加或删除幻灯片。
  • 文件体积小,主题丰富,实现简单。
  • 采用CSS过渡效果,不支持CSS过渡效果的浏览器中使用jQuery来回退。
  • 提供丰富的回调函数和公开方法。
  • 提供自动播放和无限循环的旋转木马模式。
  • 支持键盘、箭头和圆点导航。
  • 跨浏览器、跨设备:Chrome, Safari, Firefox, Opera, IE7+, IOS, Android, windows phone。
  • 同一个页面中可以生成多个幻灯片实例。
  • 幻灯片的内容可以是图片、视频等。

查看演示      下载插件

安装

可以通过npm或bower来安装该幻灯片插件。

$ bower install lightslider$ npm install lightslider
Copy after login

或者下载压缩包,在页面中引入以下文件。

<link type="text/css" rel="stylesheet" href="css/lightslider.css" /><script src="js/jquery.min.js"></script><script src="js/lightslider.js"></script>
Copy after login

使用方法

HTML结构

lightslider幻灯片的基本HTML结构如下:

<ul id="light-slider">    <li>        <h3 id="First-Slide">First Slide</h3>        <p>Lorem ipsum Cupidatat quis pariatur anim.</p>    </li>    <li>        <h3 id="Second-Slide">Second Slide</h3>        <p>Lorem ipsum Excepteur amet adipisicing fugiat velit nisi.</p>    </li>    ...</ul>
Copy after login

初始化插件

在页面DOM元素加载完毕之后,可以通过lightSlider()方法来初始化该幻灯片插件。

<script type="text/javascript">    $(document).ready(function() {        $("#light-slider").lightSlider();    });</script>
Copy after login

配置参数

该幻灯片插件可用的配置参数有:

参数 类型 默认值 描述
item number 3 同时显示的slide的数量
autoWidth boolean false 定制每一个slide的宽度
slideMove number 1 同一时间被移动的slide的数量
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 过渡动画的持续时间,单位毫秒
auto boolean false 如果设置为true,幻灯片将自动播放
pauseOnHover boolean false 鼠标滑过时停止自动播放
loop boolean false false表示在播放到最后一帧时不会跳转到开头重新播放
slideEndAnimation bolean true 允许slideEnd动画
pause number 2000 两个过渡动画之间的间隔时间
keyPress boolean false 是否允许使用键盘导航
controls boolean true 如果设置为false,prev/next按钮将不会被显示
prevHtml string '' 自定义prev按钮的HTML
nextHtml string '' 自定义next按钮的HTML
rtl boolean false 改变方向,从右到左
adaptiveHeight boolean false 基于各个slide的高度来动态调整幻灯片的高度
vertical boolean false 制作垂直幻灯片效果
verticalHeight number 500 垂直幻灯片模式中设置slide的高度(如果slide数量大于1)
vThumbWidth number 100 垂直幻灯片模式中缩略图的宽度
thumbItem number 10 同时显示缩略图的数量
pager boolean true 是否开启圆点导航
gallery boolean true 是否开启带缩略图的幻灯片模式
galleryMargin number 5 画廊和slide之间的间距
thumbMargin number 3 缩略图之间的间距
currentPagerPosition string 'middle' 缩略图的位置,可以是: 'left', 'middle', 'right'
enableTouch boolean true 是否支持移动触摸
enableDrag boolean true 是否支持桌面设备中使用鼠标拖拽切换幻灯片
freeMove boolean true 是否允许在swipe或drag的时候自由移动幻灯片
responsive object null 单独设置每一个breakpoint

回调函数

回调函数 参数 描述
onBeforeStart el 幻灯片开始加载时触发
onSliderLoad el 幻灯片被加载后立刻执行
onBeforeSlide el 每一个slide过渡动画之前被执行
onAfterSlide el 每一个slide过渡动画之后被执行
onBeforeNextSlide el 每一次"Next" slide过渡动画被执行前触发
onBeforePrevSlide el 每一次"Prev" slide过渡动画被执行前触发

公开方法

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the purpose of the <progress> element? What is the purpose of the <progress> element? Mar 21, 2025 pm 12:34 PM

The article discusses the HTML &lt;progress&gt; element, its purpose, styling, and differences from the &lt;meter&gt; element. The main focus is on using &lt;progress&gt; for task completion and &lt;meter&gt; for stati

What is the purpose of the <datalist> element? What is the purpose of the <datalist> element? Mar 21, 2025 pm 12:33 PM

The article discusses the HTML &lt;datalist&gt; element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

What are the best practices for cross-browser compatibility in HTML5? What are the best practices for cross-browser compatibility in HTML5? Mar 17, 2025 pm 12:20 PM

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

What is the purpose of the <meter> element? What is the purpose of the <meter> element? Mar 21, 2025 pm 12:35 PM

The article discusses the HTML &lt;meter&gt; element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates &lt;meter&gt; from &lt;progress&gt; and ex

How do I use the HTML5 <time> element to represent dates and times semantically? How do I use the HTML5 <time> element to represent dates and times semantically? Mar 12, 2025 pm 04:05 PM

This article explains the HTML5 &lt;time&gt; element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

How do I use HTML5 form validation attributes to validate user input? How do I use HTML5 form validation attributes to validate user input? Mar 17, 2025 pm 12:27 PM

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

What is the viewport meta tag? Why is it important for responsive design? What is the viewport meta tag? Why is it important for responsive design? Mar 20, 2025 pm 05:56 PM

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

What is the purpose of the <iframe> tag? What are the security considerations when using it? What is the purpose of the <iframe> tag? What are the security considerations when using it? Mar 20, 2025 pm 06:05 PM

The article discusses the &lt;iframe&gt; tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

See all articles