Socket
Socket
Sign inDemoInstall

ngx-hm-carousel

Package Overview
Dependencies
7
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ngx-hm-carousel

[![NPM version](https://badge.fury.io/js/ngx-hm-carousel.svg)](http://badge.fury.io/js/ngx-hm-carousel) # ngx-hm-carousel


Version published
Weekly downloads
2K
decreased by-2.17%
Maintainers
1
Install size
1.66 MB
Created
Weekly downloads
 

Changelog

Source

1.7.1

Feature

  • pan-boundary:add Input [pan-boundary] to user move picture with the container width rate, when more than that rate distance, it will go to next or prev.

Readme

Source

NPM version

A lightweight carousel UI for Angular, support mobile touch with Hammerjs.

Work with custom animation, and server-side-rendering.

Description

An Carousel that eazy to use with your custom template.

This package is design by angular and hammerjs, if you use @angular/material, I strongly recommend you use this package.

Depend on Hammerjs and resize-observer-polyfill

Support Angular 6+ and Rxjs6+

Example

https://alanzouhome.firebaseapp.com/package/NgxHmCarousel

Stackblitz Example

with custom animation

custom-breakpoint

change-show-number-dynamicly

disable-drag event

loop carousel

Install

npm install --save ngx-hm-carousel
  1. HammerJs
  • Import hammerjs in your main.ts or app.module.ts;
import 'hammerjs';

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
...
...
  • Import NgxHmCarouselModule into your main AppModule or the module where you want use.
  1. Module
import { NgxHmCarouselModule } from 'ngx-hm-carousel';

@NgModule({
  imports: [
    NgxHmCarouselModule
  ]
})
export class YourModule {}
  1. HTML

<ngx-hm-carousel
  [(ngModel)]="currentIndex"
  [show-num]="4"
  [autoplay-speed]="speed"
  [infinite]="infinite"
  [drag-many]="true"
  [aniTime]="200"
  [data]="avatars"
  class="carousel c-accent">

  <section ngx-hm-carousel-container class="content">
    <article class="item cursor-pointer"
      ngx-hm-carousel-item
      *ngFor="let avatar of avatars; let i = index"
        [ngClass]="{'visible': currentIndex===i}">
      <div class="img" (click)="click(i)"
        [style.backgroundImage]="'url('+avatar.url+')'">
        {{i}}
      </div>
    </article>
    <ng-template #infiniteContainer></ng-template>
  </section>

  <!-- only using in infinite mode or autoplay mode, that will render with-->
  <ng-template #carouselContent let-avatar let-i="index">
    <article class="item cursor-pointer"
      [ngClass]="{'visible': currentIndex===i}">
      <div class="img" (click)="click(i)"
        [style.backgroundImage]="'url('+avatar.url+')'">
        {{i}}
      </div>
    </article>
  </ng-template>

  <ng-template #carouselPrev>
    <div class="click-area">
      <i class="material-icons">keyboard_arrow_left</i>
    </div>
  </ng-template>
  <ng-template #carouselNext>
    <div class="click-area">
      <i class="material-icons">keyboard_arrow_right</i>
    </div>
  </ng-template>

  <ng-template #carouselDot let-model>
    <div class="ball bg-accent"
      [class.visible]="model.index === model.currentIndex"></div>
  </ng-template>

  <ng-template #carouselProgress let-progress>
    <div class="progress"></div>
  </ng-template>

</ngx-hm-carousel>

  1. TS
import { Component } from '@angular/core';

@Component({
  selector: 'app-drag-one',
  templateUrl: './drag-one.component.html',
  styleUrls: ['./drag-one.component.scss']
})
export class DragOneComponent {

  currentIndex = 0;
  speed = 5000;
  infinite = true;
  direction = 'right';
  directionToggle = true;
  autoplay = true;
  avatars = '1234567891234'.split('').map((x, i) => {
    const num = i;
    // const num = Math.floor(Math.random() * 1000);
    return {
      url: `https://picsum.photos/600/400/?${num}`,
      title: `${num}`
    };
  });

  constructor() { }

  click(i) {
    alert(`${i}`);
  }

}
  1. SCSS
  • this project not contain any specile style, you can custom by yourself
$transition_time:.2s;

.carousel {
  color:white;
  .content {
    display: flex;

    .item {
      width: 100%;
      padding: .5em;
      display: block;
      opacity: 0.5;

      transition: opacity 0.295s linear $transition_time;

      &.visible {
        opacity: 1;
      }

      .img {
        width: 100%;
        height: 400px;
        display: block;
        background-size: cover;
        background-position: center;
      }
    }


  }

  .ball {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: black;
    border: 2px solid;
    opacity: 0.5;

    &.visible {
      opacity: 1;
    }
  }

  .click-area {
    width: 50px;
    text-align: center;

    i {
      font-size: 3em;
    }
  }
}

View more examples

Attribute

Configuration (Input)


AttributeNecessaryDefault valueTypeLocationDescription
autoplaynofalsebooleanngx-hm-carouselcarousel auto play confing
autoplay-speedno5000 (ms)numberngx-hm-carouselauto play speed
between-delayno8000 (ms)numberngx-hm-carouseleach auto play between time
autoplay-directionno'right''left' or 'right'ngx-hm-carouselauto play direction
mourse-enablenofalsebooleanngx-hm-carouselis mourse moveover stop the auto play
autoplaynofalsebooleanngx-hm-carouselcarousel auto play confing
[breakpoint]no[]NgxHmCarouselBreakPointUpngx-hm-carouselswitch show number with own logic like boostrap scss media-breakpoint-up
show-numno1number or 'auto'ngx-hm-carouselhow many number items to show once
scroll-numno1numberngx-hm-carouselhow many number with each scroll
drag-manynofalsebooleanngx-hm-carouselis can scroll many item once, simulate with scrollbar
swipe-velocityno0.3numberngx-hm-carouselMinimal velocity required before recognizing, unit is in px per ms.
pan-boundaryno0.15numberngx-hm-carouseluser move picture with the container width rate, when more than that rate, it will go to next or prev.
alignno'left''left' or 'right''center'ngx-hm-carousel
infinitenofalsebooleanngx-hm-carouselis the carousel will move loop
datanoundefinedany[]ngx-hm-carouselthe data you using with *ngFor, it need when infinite mode or autoplay mode
aniTimeno400numberngx-hm-carouselwhen infinite is true, the animation time with item
aniClassno'transition'stringngx-hm-carouselthis class will add when carousel touch drap or click change index
aniClassAutonousing aniClassstringngx-hm-carouselthis class will add when carousel auto play
disable-dragnofalsebooleanngx-hm-carouseldisable drag event with touch and mouse pan moving
not-follow-pannofalsebooleanngx-hm-carouseldisable when drag occur the child element will follow touch point.
[(ngModel)]no0numberngx-hm-carouselYou can bind ngModel with this carousel, it will two way binding with current index. You also can use (ngModelChange)="change($event)" with that.
// the breakpoint interface
export interface NgxHmCarouselBreakPointUp {
  width: number;
  number: number;
}

Other Directive

nomal click with effect the touch event, using this event replace that.

AttributeLocationDescription
ngxHmCarouselDynamicany tagIt will dynamic load tag with element.

This Directive will Dynamin load element with previous element and next element and current element.

  • Example
<section ngx-hm-carousel-container class="content">
  <article class="item cursor-pointer"
    ngx-hm-carousel-item
    *ngFor="let item of data; let i = index">
    <div *ngxHmCarouselDynamic="i; length: data.length; index: currentI"
      class="img" [style.backgroundImage]="item.url">
    </div>
  </article>
</section>
  1. first data is this data index
  2. length is ths total length with array
  3. index is now index

FAQs

Last updated on 22 Jun 2019

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