Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/slider/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,21 @@ slider.setCurrentSlide( 2 );

## Attributes

| Attribute | Required | Values | Notes |
|-----------------|----------|-----------------|--------------------------------------------------------------------------------------------------------|
| flexible-height | No | `yes` | Whether the height of the slider changes depending on the content inside the slides |
| infinite | No | `yes` | Go back to the first slide at the end of all slides, and open the last slide when navigating backwards |
| swipe | No | `yes` | Whether to add support for swiping gestures on touch devices |
| behaviour | No | `fade`, `slide` | The default behaviour is to slide between slides. This can be updated to fade. |
| Attribute | Required | Values | Notes |
|---------------------|----------|-----------------|--------------------------------------------------------------------------------------------------------|
| flexible-height | No | `yes` | Whether the height of the slider changes depending on the content inside the slides |
| infinite | No | `yes` | Go back to the first slide at the end of all slides, and open the last slide when navigating backwards |
| swipe | No | `yes` | Whether to add support for swiping gestures on touch devices |
| behaviour | No | `fade`, `slide` | The default behaviour is to slide between slides. This can be updated to fade. |
| auto-slide-interval | No | <interval> | Interval in milliseconds. |

## Events

| Event | Notes |
|----------------|---------------------------------------------------|
| slide-set | When the current slide is set, but before sliding |
| slide-complete | After sliding is complete |
| Event | Notes |
|---------------------|--------------------------------------------------|
| slide-set | When the current slide is set, but before sliding |
| slide-complete | After sliding is complete |
| auto-slide-complete | After auto sliding is complete |

## Methods

Expand Down
29 changes: 29 additions & 0 deletions src/slider/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,35 @@
</tp-slider-nav>
<tp-slider-count current="1" total="4" format="$current / $total">1 / 4</tp-slider-count>
</tp-slider>

<br>

<!--Slider that autoplay -->
<tp-slider flexible-height="yes" infinite="yes" auto-slide-interval="3000">
<tp-slider-arrow direction="previous"><button>&laquo; Previous</button></tp-slider-arrow>
<tp-slider-arrow direction="next"><button>Next &raquo;</button></tp-slider-arrow>
<tp-slider-track>
<tp-slider-slides>
<tp-slider-slide><img src="https://picsum.photos/600/300" width="600" height="300" alt=""></tp-slider-slide>
<tp-slider-slide><img src="https://picsum.photos/600/300" width="600" height="300" alt=""></tp-slider-slide>
<tp-slider-slide><img src="https://picsum.photos/600/300" width="600" height="300" alt=""></tp-slider-slide>
<tp-slider-slide>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</tp-slider-slide>
</tp-slider-slides>
</tp-slider-track>
<tp-slider-nav>
<tp-slider-nav-item><button>1</button></tp-slider-nav-item>
<tp-slider-nav-item><button>2</button></tp-slider-nav-item>
<tp-slider-nav-item><button>3</button></tp-slider-nav-item>
<tp-slider-nav-item><button>4</button></tp-slider-nav-item>
</tp-slider-nav>
<tp-slider-count current="1" total="4" format="$current / $total">1 / 4</tp-slider-count>
</tp-slider>
</main>
</body>
</html>
28 changes: 28 additions & 0 deletions src/slider/tp-slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class TPSliderElement extends HTMLElement {

// Initialize slider.
this.slide();
this.autoSlide();
this.setAttribute( 'initialized', 'yes' );

// Event listeners.
Expand Down Expand Up @@ -407,4 +408,31 @@ export class TPSliderElement extends HTMLElement {
this.next();
}
}

/**
* Auto slide.
*/
protected autoSlide(): void {
// Auto Slide.
const autoSlideInterval: string | null = this.getAttribute( 'auto-slide-interval' );

// Check if we have an auto slider interval.
if ( ! autoSlideInterval ) {
return;
}

// Check for a valid interval.
const interval: number = parseInt( autoSlideInterval );
if ( interval <= 0 ) {
return;
}

// Run this on a timeout, rather than interval, so the interval can be controlled after
// the component is initialised.
setTimeout( (): void => {
this.next();
this.autoSlide();
this.dispatchEvent( new CustomEvent( 'auto-slide-complete' ) );
}, parseInt( autoSlideInterval ) );
}
}