Socket
Socket
Sign inDemoInstall

ngx-carousel-ease

Package Overview
Dependencies
5
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ngx-carousel-ease

ngx-carousel-ease is a versatile Angular library providing a feature-rich, simple, and performant carousel component. This library supports infinite and responsive mode, mouse and touch event. Attention has been put to accessibility, performance, and frie


Version published
Weekly downloads
7
decreased by-50%
Maintainers
1
Install size
401 kB
Created
Weekly downloads
 

Readme

Source

Description

ngx-carousel-ease is a versatile Angular library providing a feature-rich, simple, and performant carousel component. This library supports infinite and responsive mode, mouse and touch event. Attention has been put to accessibility, performance, and friendly developer experience.

Support Angular version starts at v17.

Demo

Live demonstration of the ngx-carousel-ease library here.

Installation

You can install the library using the following command:

npm i ngx-carousel-ease

Then, add the CarouselModule in the imports array of the hosting component (if standalone) or to your appModule. Finally, add your cards content within the <carousel></carousel> selector in the hosting component. Each of your card should contain the class carousel-slide.

<carousel>
  <div class="carousel-slide">...</div>
  <div class="carousel-slide">...</div>
  ...
</carousel>

Inputs

The carousel is configured by default and all inputs are optional.

NameDefaultDescription
maxWidthCarouselundefinedDefine the max width of the carousel in pixels.
infinitefalseEnable infinite loop of slides.
responsivetrueWidth of the slides will be automatically adapted. In non-responsive mode, the width of the slides won't be adapted.
autoSlidetrueEnable sliding on drag stop. Carousel will slide towards the nearest slide.
autoslideLimitPercentCard30Percentage of the card compared to mouvement to trigger automatic sliding.
autoPlayfalseEnable automatic sliding within an interval of time. In finite carousel, autoPlay will stop if the start or the end of the carousel is reached.
autoPlayInterval1500Interval of time in milliseconds for automatic sliding (autoPlay).
autoPlayAtStartfalseEnable autoPlay at start.
autoPlaySlideToScroll1Number of slides to scroll for the autoPlay.
displayAutoPlayControlstrueDisplay the play and pause autoPlay controls.
playDirectionltrDirection of the autoPlay. Accepts: ltr or rtl (left to right or right to left).
slideToShow3Number of slides to show at a time. The number of slides to show is dependant of the available space.
slideToScroll2Number of slides to scroll at a time.
strechingLimit60Limit for the stretching effect in pixels. Streching effect occurs only in finite mode and at the start or end of the carousel.
slideWidth300Width of each slide in pixels.
slideMaxWidth500Maximum width of each slide in pixels.
dotstrueDisplay navigation dots.
arrowstrueDisplay navigation arrows.
countertrueDisplay slide counter.
counterSeparator'/'Separator for the slide counter.
enableMouseDragtrueEnable mouse drag for navigation.
enableTouchtrueEnable touch drag for navigation.
gapBetweenSlides16Gap between slides in pixels.
animationTimingFn'ease-out'Timing function for the slide transition animation. Options include 'linear', 'ease-in', 'ease-out', 'ease-in-out'.
animationTimingMs300Duration of slide transition animation in milliseconds.
maxDomSize4In infinite mode, maximum number of times the number of slides present in the DOM to prevent infinite growth. Example: 6 cards x 4 = 24 maximum cards. If you want to disable this feature, pass 'Infinity' to this property.

Service

This library provides a CarouselService containing an RxJs Subject onSlideChange that is triggered at every slide change. onSlideChange returns an object containing the current slide number and the carousel ID (useful if multiple carousel on a page to target a specific carousel instance). The slide number and carousel ID are zero indexed.

Inject the CarouselService through regular dependency injection in your hosting component.

ngOnInit() {
  this.carouselService.onSlideChange.subscribe((slideAndID) => {
    // change carousel colors, trigger a function, ...
  });
}

The third example in the demo uses this functionnality.

Style Customisation

Given the nearly infinite and subjective possibilities for customization, a predefined choice of themes (such as light or dark) has not been incorporated.

If you wish to customize the theme or parts of the carousel, add encapsulation: ViewEncapsulation.None to the hosting parent component and erase the default styles. Find the corresponding classes by inspecting the DOM.

The following example changes the defaulted blue arrows:

.carousel-container .prev,
.carousel-container .next {
  background: red !important;
}

SSR (Server Side Rendering)

This library supports Server Side Rendering (SSR). The carousel will not instantiate during server-side execution, as it requires access to the DOM API, preventing errors.

DX Friendly

Ensuring a seamless Developer Experience (DX), basic validation is performed on the parameters passed to the carousel. An error is raised in case of abnormal parameters. Please note that common sense mistakes, such as passing a negative value for slide to show or a negative carousel max width, are not validated. This library has been meticulously documented.

Performance

Emphasis has been placed on performance, adopting ChangeDetectionStrategy.OnPush and utilizing translate3d instead of translateX. This choice aims to enable hardware acceleration in specific scenarios, which can contribute to a smoother and more efficient user experience. By default, if infinite mode is enabled, a function will prevent infinite DOM growth by removing invisible cards.

Change log

Version 0.0.7: Support for dynamically HTML generated content (ngFor, @for) for slide creation. Correction of a validation bug.

Version 0.0.9: Change in the behavior of the auto slide. Auto slide will now occur on drag stop (when the user releases the mouse), and will automatically slide towards the nearest slide based on the set threshold. Auto slide is set to true by default.

Version 0.1.1: Fixed a race condition that could occur betweeen evaluation of the template and initialisation of the variables.

Version 0.1.2: Adding an autoPlay feature.

Report a Bug

Please provide a detailed description of the encountered bug, including your carousel configuration and the steps/actions that led to the issue. An accurate description will help me to reproduce the issue.

Ngx-ease serie

You like this library? Discover the ngx-ease serie here.

Keywords

FAQs

Last updated on 29 Feb 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc