summaryrefslogtreecommitdiff
path: root/README.md
blob: cf174f949b0be51570fe7e4211943767fbfecd4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# ♎️ Libra.js

A lightweight, focused, vanilla JavaScript image lightbox library, only around ✨**3KB** after minified.

![screenshot](https://github.com/BigCoke233/libra/blob/master/screenshot.gif)

_*GIF might appear slower than actual._

## Usage

Grab [libra.min.js](https://github.com/BigCoke233/libra/blob/master/dist/libra.min.js) and put it in your project.

Then import it as a module:

```html
<script type="module">
    import LightBox from '/dist/libra.min.js';
    new LightBox();
</script>
```

Make sure your images all have their `data-libra` attribute, or any other selector you may specify in configuration.

```html
<div class="libra">
  <img data-libra src="1.jpg" />
  <img data-libra src="2.jpg" />
  <!-- ... -->
</div>
```

Also, include [libra.css](https://github.com/BigCoke233/libra/blob/master/src/libra.css).

```html
<link rel="stylesheet" href="/src/libra.css" />
```

## Configuration

You can configure Libra.js by passing an object to the constructor. The defaults are:

```js
new LightBox({
  selector: '[data-libra]', // Selector for images to be lightboxed
  margin: 50,               // Margin around the lightbox
  offset: { x: 0, y: 0 }    // Offset for the lightbox position
});
```

## Development

```
npm install
npm run build
```

## Philosophy

### Why I made Libra.js

I've been using [Fancybox](https://fancyapps.com/fancybox/) on my blog for a long time. While it is an excellent library, it also includes lots of features I don't need, which can slow down performance and increase the bundle size. After searching available alternatives, I found most of them either not well maintained or just as heavy. So I developed Libra.js for my own use, and I hope you find it useful, too!

### Things I won't do with Libra.js

- I won't support IE or older browsers. Please use a modern browser and make sure it's up to date.
- I won't add too many features or configurations for customization. You just click on an image and see the zoomed-in and centered version. That's all.

### Why it's called Libra.js

It's a light-box plugin that focuses on simplicity, so I called it "libo" at first, which is a combination of the first 2 letters of "light" and "box". Then I realized that "libo" sounds a lot like "libra", which is a zodiac sign. I decided to keep the name "libra" because it's a more recognizable and memorable name.

## License

MIT