Glide.js是一款轻盈灵活的jQuery滑块/转盘插件(ES6 JavaScript滑块/转盘库),可帮助您创建具有快速和高性能CSS3转换的响应式和触摸式滑块。
1.使用NPM安装并下载库。
# NPM $ npm install @glidejs/glide --save
2.将Glide.js导入到您的项目中。
// Core Stylesheet @import "node_modules/@glidejs/glide/src/assets/sass/glide.core"; // Theme Stylesheet @import "node_modules/@glidejs/glide/src/assets/sass/glide.theme"; import Glide from '@glidejs/glide'
3.或者直接加载文档中的JavaScript和CSS文件。
<!-- Local --> <link rel="stylesheet" href="dist/css/glide.core.min.css"> <link rel="stylesheet" href="dist/css/glide.theme.min.css"> <script src="dist/glide.min.js"></script> <!-- CDN --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@glidejs/[email protected]/dist/css/glide.core.min.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@glidejs/[email protected]/dist/css/glide.theme.min.css"> <script src="https://cdn.jsdelivr.net/npm/@glidejs/[email protected]/dist/glide.min.js"></script>
4.为幻灯片、分页项目符号和导航箭头创建html。
<div class="glide"> <!-- Slides here --> <div class="glide__track" data-glide-el="track"> <ul class="glide__slides"> <li class="glide__slide">Slide 1</li> <li class="glide__slide">Slide 2</li> <li class="glide__slide">Slide 3</li> </ul> </div> <!-- Navigation --> <div class="glide__arrows" data-glide-el="controls"> <button class="glide__arrow glide__arrow--left" data-glide-dir="<">prev</button> <button class="glide__arrow glide__arrow--right" data-glide-dir=">">next</button> </div> <!-- Pagination --> <div class="glide__bullets" data-glide-el="controls[nav]"> <button class="glide__bullet" data-glide-dir="=0"></button> <button class="glide__bullet" data-glide-dir="=1"></button> <button class="glide__bullet" data-glide-dir="=2"></button> </div> </div>
5.为滑块创建自定义控件(可选)。
<div data-glide-el="controls"> <button data-glide-dir="<">Previous</button> <button data-glide-dir=">">Next</button> <button data-glide-dir="<<">First</button> <button data-glide-dir=">>">Last</button> <button data-glide-dir="=1">Goto The Slide 2</button> </div>
6.使用默认设置初始化Glide.js。就是这样。
new Glide('.glide').mount();
7.自定义滑块的可能选项。
new Glide('.glide', { // Auto change slides after specifed interval. autoplay: 4000, // Slider type. // carousel, slider or slideshow. type: 'carousel', // Start slider at specifed slide number. startAt: 1, // Pause autoplay on mouseover the slider. hoverpause: true, // Change slide on left/right keyboard arrow press. keyboard: true, // The number of slides to show per screen perView: 1, // 'center' or 1,2,3... focusAt: 0, // Space between slides gap: 10, // Stop running perView number of slides from the end bound: false, // Minimal touch-swipe distance to need to change slide. // False for turning off touch. swipeThreshold: 80, // Maximum number of slides moved per single swipe or drag perTouch: false, // Alternate moving distance ratio of swiping and dragging touchRatio: .5, // Angle required to activate slides moving touchAngle: 45, // Minimal drag distance to need to change slide. // False for turning off drag. dragThreshold: 120, // Animation duration in ms. animationDuration: 400, // Animation easing CSS function. animationTimingFunc: 'cubic-bezier(0.165, 0.840, 0.440, 1.000)', // Call the resize events at most once per every wait in milliseconds. throttle: 16, // Enable infinite loop on slider type rewind: true, // Duration of the rewinding animation rewindDuration: 800, // 'ltr' or 'rtl' direction: // The value of the future viewports which have to be visible in the current view // e.g. 100 or { before: 100, after: 50 } peek: 0, // Options applied at specified media breakpoints breakpoints: {}, // Default CSS classes classes: { direction: { ltr: 'glide--ltr', rtl: 'glide--rtl' }, slider: 'glide--slider', carousel: 'glide--carousel', swipeable: 'glide--swipeable', dragging: 'glide--dragging', cloneSlide: 'glide__slide--clone', activeNav: 'glide__bullet--active', activeSlide: 'glide__slide--active', disabledArrow: 'glide__arrow--disabled' } })
8.属性和API方法。
// the current slide index glide.index // get the option value glide.settings.OptName // get the slider type glide.type // get the slider status glide.disabled // enable the slider glide.mount(); // update the option glide.update({ options here }); // play the slider glide.play(); // pause the slider glide.pause(); // enable the slider glide.enable(); // disable the slider glide.disable(); // destroy the slider glide.destroy(); // go to the next slide // see more in the controls section glide.go('>'); // check the slider type glide.isType('slider'); glide.isType('carousel');
9.事件处理程序。
glide.on('mount.before', function() { // befoure mount }) glide.on('mount.after', function() { // after mount }) glide.on('update', function() { // after the settings changed }) glide.on('play', function() { // when playing }) glide.on('pause', function() { // when paused }) glide.on('build.before', function() { // before setting up a slider to its initial state }) glide.on('build.bafter', function() { // after setting up a slider to its initial state }) glide.on('run.before', function(move) { // before running }) glide.on('run', function(move) { // when running }) glide.on('run.after', function(move) { // after running }) glide.on('run.offset', function(move) { // after calculating new index and making a transition }) glide.on('run.start', function(move) { // after calculating the new index, but before making a transition }) glide.on('run.end', function(move) { // after calculating the new index, but before making a transition }) glide.on('move', function(movement) { // on move }) glide.on('move.after', function(movement) { // after moving }) glide.on('resize', function() { // on window resize }) glide.on('swipe.start', function() { // swipe.start }) glide.on('swipe.move', function() { // swipe.move }) glide.on('swipe.end', function() { // swipe.end }) glide.on('translate.jump', function(movement) { // before a translate applies })
版本3.6.0(2022-09-27)
v3.5.2 (2021-11-29)
v3.5.1 (2021-11-23)
v3.5.0 (2021-11-22)
第3.4.0版(2019-09-20)
第3.3.0版(2019-08-21)
2017-01-22
2016-08-07
2016-06-05
2016-03-17
2016-02-05
2015-12-21
2015-11-08
2015-11-06
2015-08-22
2015-08-12
2015-07-29
2015-07-22
2015-07-13
2015-07-07
2015-06-13
2015-06-06
2015-06-03
2015-05-24
2015-05-15
2015-05-04
2015-04-30
2015-04-23
2014-11-25
2014-07-12
2014-02-26
2014-02-21
2014-02-20
2014-02-11
2014-02-02
2013-12-11
2013-12-06
v1.0.4 (2013-11-04)