一个灵活、响应迅速、移动友好的JavaScript插件可以帮助您在桌面和移动网站上创建图像灯箱和图库灯箱。
1.加载简单灯箱.最小.css
在页眉和简单灯箱.min.js
在网页的页脚部分。
<link href="dist/simple-lightbox.min.css" rel="stylesheet" /> <!-- As A Vanilla JavaScript Plugin --> <script src="dist/simple-lightbox.min.js"></script> <!-- For legacy browsers --> <script src="dist/simple-lightbox.legacy.min.js"></script> <!-- As A jQuery Plugin --> <script src="/path/to/cdn/jquery.min.js"></script> <script src="dist/simple-lightbox.jquery.min.js"></script>
2.将您的所有图像插入到图库容器中。该插件将自动从中高音
的属性国际货币基金组织
标签要对图像进行分组,只需将rel属性添加到链接中,如下所示:
<div class="gallery"> <a href="1.jpg" class="big" rel="rel1"> <img src="thumb1.jpg" alt="" title="Image 1"> </a> <a href="2.jpg" class="big" rel="rel1"> <img src="thumb2.jpg" alt="" title="Image 2"> </a> <a href="3.jpg" class="big" rel="rel2"> <img src="thumb3.jpg" alt="" title="Image 3"> </a> <a href="4.jpg" class="big" rel="rel2"> <img src="thumb4.jpg" alt="" title="Image 4"> </a> </div>
3.使用默认选项调用插件以启用灯箱。
// As A Vanilla JavaScript Plugin var gallery = new SimpleLightbox('.gallery a', { /* options */ }); // As A jQuery Plugin --> var gallery = $('.gallery a').simpleLightbox({ /* options */ });
4.具有默认值的完全自定义选项。
// default source attribute sourceAttr: 'href', // shows fullscreen overlay overlay: true, // shows loading spinner spinner: true, // shows navigation arrows nav: true, // text for navigation arrows navText: ['←','→'], // shows image captions captions: true, captionDelay: 0, captionSelector: 'img', captionType: 'attr', captionPosition: 'bottom', captionClass: '', // captions attribute (title or data-title) captionsData: 'title', // shows close button close: true, // text for close button closeText: 'X', // swipe up or down to close gallery swipeClose: true, // show counter showCounter: true, // file extensions fileExt: 'png|jpg|jpeg|gif', // weather to slide in new photos or not, disable to fade animationSlide: true, // animation speed in ms animationSpeed: 250, // image preloading preloading: true, // keyboard navigation enableKeyboard: true, // endless looping loop: true, // group images by rel attribute of link with same selector rel: false, // closes the lightbox when clicking outside docClose: true, // how much pixel you have to swipe swipeTolerance: 50, // lightbox wrapper Class className: 'simple-lightbox', // width / height ratios widthRatio: 0.8, heightRatio: 0.9, // scales the image up to the defined ratio size scaleImageToRatio: false, // disable right click disableRightClick: false, // disable page scroll disableScroll: true, // show an alert if image was not found alertError: true, // alert message alertErrorMessage: 'Image not found, next image will be loaded', // additional HTML showing inside every image additionalHtml: false, // enable history back closes lightbox instead of reloading the page history: true, // time to wait between slides throttleInterval: 0, // Pinch to Zoom feature for touch devices doubleTapZoom: 2, maxZoom: 10, // adds class to html element if lightbox is open htmlClass: 'has-lightbox', // RTL mode rtl: false, // elements with this class are fixed and get the right padding when lightbox opens fixedClass: 'sl-fixed', // fade speed in ms fadeSpeed: 300, // whether to uniqualize images uniqueImages: true, // focus the lightbox on open to enable tab control focus: true,
5.API方法。
// Opens the lightbox gallery.open(); // Closes the lightbox gallery.close(); // Goto next image gallery.next(); // Goto previous image gallery.prev(); // re-init the lightbox gallery.refresh(); // get lightbox data gallery.getLighboxData(); // Destroys the lightbox gallery.destroy();
6.事件。
打开简易照明盒
:在灯箱打开之前点火打开的简易灯箱
:灯箱打开后起火关闭简易照明盒
:在灯箱关闭之前点火封闭式简易灯箱
:灯箱关闭后起火更改简易照明盒
:在图像更改之前激发已更改。简单灯箱
:更改图像后激发下一个简单灯箱
:在下一个图像到达之前激发nextDone.simplelightbox
:到达下一个图像后发生火灾上一个简易工具箱
:在上一个图像到达之前激发上一篇Done.simple灯箱
:在上一个图像到达后激发nextImageLoaded.简单灯箱
:在加载下一个图像后激发(如果预加载已激活)prevImageLoaded.简单灯箱
:在加载上一个图像后激发(如果预加载已激活)错误。简单框
:在图像加载错误时激发$('.gallery a').on('open.simplelightbox', function () { // do something⦠});
v2.13.0版本(2023-03-29)
v2.12.1版本(2023-01-12)
v2.12.0版本(2023-01-12)
v2.11.0版本(2022-11-21)
v2.10.4版本(2022-10-13)
v2.10.3版本(2022-03-21)
v2.10.2版本(2022-01-27)
v2.10.1 (2021-11-16)
v2.10.0 (2021-11-10)
v2.9.0 (2021-09-30)
v2.8.1 (2021-09-08)
v2.8.0 (2021-06-24)
v2.8.0 (2021-04-21)
v2.7.2 (2021-04-21)
v2.7.2 (2021-04-14)
v2.7.1 (2021-04-13)
v2.7.0版本(2020-11-19)
v2.6.0版本(2020-10-29)
v2.5.0版本(2020-10-21)
v2.4.1版本(2020-10-19)
v2.4.0/v2.3.0版本(2020-10-13)
v2.2.2版本(2020-09-29)
v2.2.1版本(2020-05-19)
v2.1.5版本(2020-04-29)
v2.1.4版本(2020-04-07)
v2.1.3版本(2020-03-17)
v2.1.2版本(2020-02-26)
v2.1.1版本(2020-02-18)
v2.1.0版本(2020-02-17)
2019-06-06
2019-04-11
2019-03-24
2019-02-21
2019-02-15
2019-02-07
2018-11-27
2018-10-17
2018-10-05
2018-06-20
2018-06-20
2018-03-09
2018-01-29
2017-11-24
2017-07-19
2017-05-15
2017-04-04
2017-03-22
2017-01-11
2016-11-24
2016-11-13
2016-10-31
2016-10-25
2016-10-13
2016-07-27
2016-07-03
2016-06-06
2016-05-03
2016-04-12
2016-02-29
2016-02-08
2016-01-23
2016-01-08
2016-01-04
2015-12-15
2015-12-03
2015-11-08
2015-11-03
2015-10-27
2015-10-26
2015-10-15
2015-10-13
2015-10-03
2015-09-14
2015-09-05
2015-08-17
2015-07-06
2015-05-31