Skip to content
This repository was archived by the owner on Feb 24, 2023. It is now read-only.

Commit 03bde25

Browse files
author
Łukasz Florczak
committed
prevArrow, nextArrow and better arrow positioning (fixed #30)
1 parent ce7c433 commit 03bde25

File tree

3 files changed

+59
-27
lines changed

3 files changed

+59
-27
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ Every first-level child of `<agile>` is a new slide.
5050
| Parameter | Type | Default | Description |
5151
| --- | --- | --- | --- |
5252
| arrows | boolean | `true` | Enable prev/next arrows |
53+
| prevArrow | string (HTML/SVG) | `<svg>` | Prev arrow code – more in „Arrows” section |
54+
| nextArrow | string (HTML/SVG) | `<svg>` | Next arrow code – more in „Arrows” section |
5355
| autoplay | boolean | `false` | Enable autoplay |
5456
| autoplaySpeed | integer (ms) | `3000` | Autoplay interval in milliseconds |
5557
| dots | boolean | `true` | Enable dot indicators/pagination |
@@ -68,6 +70,34 @@ Every first-level child of `<agile>` is a new slide.
6870
</agile>
6971
```
7072

73+
## Arrows
74+
75+
By default carousel contains SVG arrows. You can change them using CSS or `prevArrow` & `nextArrow` parameters.
76+
77+
There are two important things:
78+
79+
1. You should put your SVG/HTML code in one line, without new line chars etc.
80+
2. You should define arrows code as variables in `data()`.
81+
82+
### Example
83+
84+
``` vue
85+
<agile :prevArrow="left" :nextArrow="right">
86+
...
87+
</agile>
88+
```
89+
90+
```js
91+
export default {
92+
data () {
93+
return {
94+
left: '<svg x="0px" y="0px" viewBox="0 0 24 24"><path d="M16.2,21c0.3,0,0.5-0.1,0.7-0.3c0.4-0.4,0.4-1,0-1.4L9.6,12L17,4.7c0.4-0.4,0.4-1,0-1.4c-0.4-0.4-1-0.4-1.4,0L6.8,12l8.8,8.7C15.7,20.9,16,21,16.2,21z"/></svg>',
95+
right: '<svg x="0px" y="0px" viewBox="0 0 24 24"><path d="M7.8,21c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l7.4-7.3L7,4.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l8.8,8.7l-8.8,8.7C8.3,20.9,8,21,7.8,21z"/></svg>'
96+
}
97+
}
98+
}
99+
```
100+
71101
## SSR Support
72102

73103
The component uses browser specific attributes (like `window` and `document`). It is necessary, so probably the only option is to run vue-agile only on the client-side. It was tested on [nuxt v1.0.0-rc7](https://github.com/nuxt/nuxt.js/releases/tag/v1.0.0-rc7) and works fine.

demo/scss/main.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ pre[class*=language-] {
298298
background-color: rgba(#000, .5);
299299
}
300300

301-
#arrow-svg {
301+
svg {
302302
fill: #fff;
303303
}
304304
}
@@ -307,7 +307,7 @@ pre[class*=language-] {
307307
display: none;
308308
}
309309

310-
#arrow-svg {
310+
svg {
311311
fill: rgba(#fff, .4);
312312

313313
@include md {

src/Agile.vue

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
:style="{width: width.track + 'px', transform: 'translate(-' + transform + 'px)', transition: 'transform ' + timing_ + ' ' + transitionDelay + 'ms'}">
66
<slot></slot>
77
</div>
8-
9-
<ul v-if="dots_" class="agile__dots">
10-
<li v-for="n in slidesCount" class="agile__dot"
11-
:class="{'agile__dot--current': n - 1 === currentSlide}">
12-
<button @click="setSlide(n - 1)">{{n}}</button>
13-
</li>
14-
</ul>
15-
16-
<button v-if="arrows_" class="agile__arrow agile__arrow--prev"
17-
:disabled="currentSlide === 0 && !infinite_" @click="prevSlide" v-html="arrow_">
18-
</button>
19-
<button v-if="arrows_" class="agile__arrow agile__arrow--next"
20-
:disabled="currentSlide === slidesCount - 1 && !infinite_" @click="nextSlide" v-html="arrow_">
21-
</button>
228
</div>
9+
10+
<ul v-if="dots_" class="agile__dots">
11+
<li v-for="n in slidesCount" class="agile__dot"
12+
:class="{'agile__dot--current': n - 1 === currentSlide}">
13+
<button @click="setSlide(n - 1)">{{n}}</button>
14+
</li>
15+
</ul>
16+
17+
<button v-if="arrows_" class="agile__arrow agile__arrow--prev"
18+
:disabled="currentSlide === 0 && !infinite_" @click="prevSlide" v-html="prevArrow_">
19+
</button>
20+
<button v-if="arrows_" class="agile__arrow agile__arrow--next"
21+
:disabled="currentSlide === slidesCount - 1 && !infinite_" @click="nextSlide" v-html="nextArrow_">
22+
</button>
2323
</div>
2424
</template>
2525

@@ -28,9 +28,14 @@
2828
name: 'agile',
2929
3030
props: {
31-
arrow: {
31+
prevArrow: {
3232
type: String,
33-
default: '<svg version="1.1" id="arrow-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 240.823 240.823" style="enable-background:new 0 0 240.823 240.823;" xml:space="preserve"><g><path id="arrow" d="M183.189,111.816L74.892,3.555c-4.752-4.74-12.451-4.74-17.215,0c-4.752,4.74-4.752,12.439,0,17.179 l99.707,99.671l-99.695,99.671c-4.752,4.74-4.752,12.439,0,17.191c4.752,4.74,12.463,4.74,17.215,0l108.297-108.261 C187.881,124.315,187.881,116.495,183.189,111.816z"/></g></svg>'
33+
default: '<svg x="0px" y="0px" viewBox="0 0 24 24"><path d="M16.2,21c0.3,0,0.5-0.1,0.7-0.3c0.4-0.4,0.4-1,0-1.4L9.6,12L17,4.7c0.4-0.4,0.4-1,0-1.4c-0.4-0.4-1-0.4-1.4,0L6.8,12l8.8,8.7C15.7,20.9,16,21,16.2,21z"/></svg>'
34+
},
35+
36+
nextArrow: {
37+
type: String,
38+
default: '<svg x="0px" y="0px" viewBox="0 0 24 24"><path d="M7.8,21c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l7.4-7.3L7,4.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l8.8,8.7l-8.8,8.7C8.3,20.9,8,21,7.8,21z"/></svg>'
3439
},
3540
3641
arrows: {
@@ -110,7 +115,8 @@
110115
track: 0
111116
},
112117
slidesToShow: 1,
113-
arrow_: this.arrow,
118+
prevArrow_: this.prevArrow,
119+
nextArrow_: this.nextArrow,
114120
arrows_: this.arrows,
115121
autoplay_: this.autoplay,
116122
autoplaySpeed_: this.autoplaySpeed,
@@ -479,7 +485,7 @@
479485
480486
&__arrow {
481487
border: none;
482-
bottom: 10px;
488+
bottom: -10px;
483489
margin: 0;
484490
padding: 0;
485491
position: absolute;
@@ -491,26 +497,22 @@
491497
}
492498
493499
&:hover {
494-
#arrow-svg {
500+
svg {
495501
fill: #333;
496502
}
497503
}
498504
499505
&--prev {
500506
left: 0;
501-
502-
#arrow-svg {
503-
transform: scale(-1, 1);
504-
}
505507
}
506508
507509
&--next {
508510
right: 0;
509511
}
510512
511-
#arrow-svg {
513+
svg {
512514
fill: #888;
513-
height: 20px;
515+
height: 24px;
514516
transition-duration: .3s;
515517
}
516518
}

0 commit comments

Comments
 (0)