22 |
23 |
80 |
81 |
172 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## This project is now archived. We don't use carousels any more, [and](https://powerdigitalmarketing.com/blog/why-you-should-not-use-a-carousel-on-your-website/#gref) [you](https://www.impactplus.com/blog/why-homepage-carousels-are-bad#:~:text=Carousels%20may%20seem%20flashy%20and,reflects%20badly%20on%20your%20brand.) [shouldn't](https://thegood.com/insights/ecommerce-image-carousels/) [either](https://cxl.com/blog/dont-use-automatic-image-sliders-or-carousels/).
2 |
3 |
4 |
5 |
6 |
7 | ## Svelte Carousel
8 |
9 | [](http://standardjs.com) [](https://circleci.com/gh/beyonk-adventures/svelte-carousel) [](https://v2.svelte.dev) [](https://svelte.dev)
10 |
11 | Svelte Carousel / Slider
12 |
13 | This is a ground-up rewrite of the original Svelte Carousel/Slider using Svelte v3, and [Siema](https://github.com/pawelgrzybek/siema), the goal being a fully working carousel with a tiny size.
14 |
15 | ## Usage
16 |
17 | This library is pure javascript, so can be used with any framework you like.
18 |
19 | ### Demo
20 |
21 | The [simplest possible demo](https://svelte.dev/repl/3953567d530b41d087ab7eaa8e7e632a?version=3.22.3)
22 |
23 | ```
24 | npm install
25 | npm run dev # http://localhost:12001
26 | ```
27 |
28 | ### To use within a Svelte application:
29 |
30 | ```bash
31 | npm i -D @beyonk/svelte-carousel
32 | ```
33 |
34 | ## Usage
35 |
36 | ```jsx
37 |
38 |
Slide 1
39 |
Slide 2
40 |
Slide 3
41 |
Slide 4
42 |
43 |
44 |
48 | ```
49 |
50 | ### Options
51 |
52 | #### Controls
53 |
54 | You can set the controls to be anything you like, though the default height and width are set to 40px. Just use the slots available to insert your own content.
55 |
56 | ```bash
57 | npm i -D svelte-feather-icons
58 | ```
59 |
60 | ```jsx
61 |
62 |
63 |
64 |
65 |
Slide 1
66 | ...
67 |
Slide n
68 |
69 |
70 |
71 |
72 |
73 |
77 | ```
78 |
79 | If you need to override height and width, you can use CSS:
80 |
81 | ```css
82 | .control :global(svg) {
83 | width: 100%;
84 | height: 100%;
85 | color: #fff;
86 | border: 2px solid #fff;
87 | border-radius: 32px;
88 | }
89 | ```
90 |
91 | #### Attributes
92 |
93 | You can pass the following attributes:
94 |
95 | | Attribute | Type | Default Value | Description |
96 | |-----------|---------|---------------|------------------------------------------------------------------------------------------------------------------------------|
97 | | loop | boolean | true | At the end of the carousel, loop through to the first slide again, seamlessly |
98 | | perPage | integer | 3 | Number of slides on a single page. Note that this needs to be less than or equal to the number of slides in your carousel |
99 | | autoplay | integer | 0 | Auto-change slide at an interval (in milliseconds). 0 means don't autoplay. |
100 | | duration | number | 200 | Slide transition duration in milliseconds. |
101 | | easing | string | 'ease-out' | It is like a CSS transition-timing-function — describes acceleration curve. |
102 | | startIndex | number | 0 | Index (zero-based) of the starting slide. |
103 | | draggable | boolean | true | Use dragging and touch swiping. |
104 | | multipleDrag | boolean | true | Allow dragging to move multiple slides. |
105 | | dots | boolean | true | Toggles visibility of slider dots.
106 | | controls | boolean | true | Toggles visibility of slider controls. dots. |
107 | | threshold | number | 20 | Touch and mouse dragging threshold (in px). |
108 | | rtl | boolean | false | Enables layout for languages written from right to left (like Hebrew or Arabic). |
109 |
110 | perPage can also be set to a responsive object, to change the number of slides based on screen width:
111 |
112 | ```jsx
113 |
114 | // will show 1 slide below 500px width, 2 at 500, 3 at 800.
115 | ```
116 |
117 | ### Events
118 |
119 | The Carousel components emits the following events:
120 |
121 | | Name | Data | Description |
122 | |----------|--------------------------------|--------------------------------------------------------------------------------|
123 | | `change` | `{ currentSlide, slideCount }` | `currentSlide`: The current slide index. Can be a positive or negative integer. `slideCount`: The number of slides. |
124 |
125 |
126 | ### Actions
127 |
128 | You can call left, right, go(slideNumber), pause and resume functions on the slider. For example, for pausing the autoslide while the mouse is hover the carousel
129 |
130 | ```jsx
131 |
132 |