快速入门
-
将最新版本作为zip文件下载
或使用包管理器...
Bower:bower install lightbox2 --save
NPM:npm install lightbox2 --save
-
Open up the zip file and take a peek at the barebones, working example that is included in the
/examples
folder. -
Ready to set Lightbox up on your page? Start by including the Lightbox CSS and Javascript. You can grab both these files from the
/dist
folder.- Include the CSS at the top of your page in your
<head>
tag:<link href="path/to/lightbox.css" rel="stylesheet">
- Include the Javascript at the bottom of your page before the closing
</body>
tag:<script src="path/to/lightbox.js"></script>
- Include the CSS at the top of your page in your
-
Make sure jQuery, which is required by Lightbox, is also loaded.
- If you already use jQuery on your page, make sure it is loaded before
lightbox.js
. jQuery 1.7 or greater is required. - If you are not currently using jQuery, I've created a packaged file that includes both Lightbox and jQuery. Include
dist/js/lightbox-plus-jquery.js
instead oflightbox.js
.
- If you already use jQuery on your page, make sure it is loaded before
- Confirm that the four images loaded by
lightbox.css
are in the correct location. You can grab the images from the/dist/images
folder.
用HTML初始化
- Add a
data-lightbox
attribute to any image link to enable Lightbox. For the value of the attribute, use a unique name for each image. For example:
Optional: Add a<a href="images/image-1.jpg" data-lightbox="image-1" data-title="My caption">Image #1</a>
data-title
attribute if you want to show a caption. - If you have a group of related images that you would like to combine into a set, use the same
data-lightbox
attribute value for all of the images. For example:<a href="images/image-2.jpg" data-lightbox="roadtrip">Image #2</a> <a href="images/image-3.jpg" data-lightbox="roadtrip">Image #3</a> <a href="images/image-4.jpg" data-lightbox="roadtrip">Image #4</a>
浏览器支持
Lightbox2 has been tested successfully in the following browsers:
- Internet Explorer.
Thelightbox-plus-jquery.js
file includes jQuery v2.x and supports IE 9+. If you want to support IE 6, 7, and 8, use your own copy of jQuery v1.x withlightbox.js
. - Chrome
- Safari
- Firefox
- iOS Safari
- iOS Chrome
- Android Browser
- Android Chrome
许可
Lightbox2 is licensed under The MIT License.
- 100% Free. Lightbox is free to use in both commercial and non-commercial work.
- Attribution is required.This means you must leave my name, my homepage link, and the license info intact. None of these items have to be user-facing and can remain within the code.
帮助
Have a question about how to use Lightbox?
Follow the steps below to get help. Make sure you have read the documentation on this page and looked at the included example first.
- Search Stackoverflow to see if other people have run into the same issue you are having.
- If your issue is unique, then post a new question on Stackoverflow. Use the
lightbox2
tag.
Do not use Github Issues to report personal support requests.
Found a bug?
If you find a bug, follow the instructions in the Contribution Guildelines to report the issue.