---
layout: default
title: "PhotoSwipe Documentation: Getting Started"
h1_title: Getting Started
description: PhotoSwipe image gallery getting started guide.
addjs: true
canonical_url: http://photoswipe.com/documentation/getting-started.html
buildtool: true
markdownpage: true
---
开始之前应该知道的第一件事:
- PhotoSwipe 不是一个简单的 jQuery 插件,至少需要基本的 JavaScript 知识才能安装。
- PhotoSwipe 需要预定义的图像尺寸([more about this](faq.html#image-size))。
- 如果你在无响应的网站上使用 PhotoSwipe –控件将在移动设备上进行缩放(当整个页面被缩放时)。因此,你将需要实现自定义控件(例如,在右上角的单个大型关闭按钮)。
- 文档中的所有代码都是纯 VanillaJS,并支持 IE8 及以上版本。如果你的网站或应用程序使用了一些 JavaScript framework (比如 jQuery 或 MooTools),或者你不需要支持旧的浏览器——请随意简化代码。
- 避免为移动设备提供大图片(大于 2000x1500px),因为它们会大大降低动画性能,并可能导致崩溃(尤其是在 iOS Safari 上)。可能的解决方案:[提供响应图像](responsive-images.html),或在单独的页面上打开图像,或使用支持图像平铺的库(例如 [Leaflet](http://leafletjs.com/))([more in FAQ](faq.html#mobile-crash))。
## 初始化
### 第一步:包含 JS 和 CSS 文件
你可以在 [dist/](https://github.com/dimsemenov/PhotoSwipe/tree/master/dist) 的 [GitHub](https://github.com/dimsemenov/PhotoSwipe)库文件夹中找到它们。Sass 和未编译的 JS 文件在 [src/](https://github.com/dimsemenov/PhotoSwipe/tree/master/src) 文件夹中。如果你计划修改现有的样式,我建议你使用 Sass,因为那里的代码是结构化和注释的。
```html
```
不管你将如何以及在哪里包含 JS 和 CSS 文件。只有在调用 `new PhotoSwipe()` 时,才执行代码。所以,如果你不需要 PhotoSwipe 一开始就打开文件,可以随时推迟加载。
PhotoSwipe 还支持 AMD 加载程序(如 RequireJS)和 CommonJS,可以这样使用它们:
```javascript
require([
'path/to/photoswipe.js',
'path/to/photoswipe-ui-default.js'
], function( PhotoSwipe, PhotoSwipeUI_Default ) {
// var gallery = new PhotoSwipe( someElement, PhotoSwipeUI_Default ...
// gallery.init()
// ...
});
```
此外,你还可以通过 bower(“bower install PhotoSwipe ”)或 [NPM](https://www.npmjs.com/package/photoswipe)(“npm install PhotoSwipe ”)安装它。
### 步骤 2:添加 PhotoSwipe (。pswp)元素到 DOM
你可以通过 JS 动态地添加 HTML 代码(直接在初始化之前),或者最初将其放在页面中(就像在演示页面中所做的那样)。这段代码可以附加到任何地方,但理想的情况是在结束 `