8.1.9 • Published 4 years ago

ff-carousel v8.1.9

Weekly downloads
51
License
-
Repository
-
Last release
4 years ago

Build Status

ff-carousel

##Getting started

Installation

#####To install this library, run:

$ npm install ff-carousel --save
Include to your module

AppModule

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';

// Import library
import {FFCarouselModule} from 'ff-carousel';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    // Specify library as an import
    FFCarouselModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Once ff-carousel is imported, you can use its directive in your Angular application:

<!-- You can now use library component in your.component.html -->
<ff-carousel></ff-carousel>

You should put slides (1), indicators (2) and arrows (3*) as ng-content:

<ff-carousel>
<!-- (1) You should mark you slide with *ffCarouselItem directive to let ff-carousel know that it's slide -->
<!-- Then you can make your own structure and styles for slide -->
    <div *ffCarouselItem class="slide-wrapper">
      <img src="first_slide_image.jpg" class="slide-img">
      <h2 class="slide-header"></h2>
      <p class="slide-description">Lorem ipsum dolor sit amet, consectetur adipisicing elit. 
         Exercitationem illo mollitia natus nihil
         perspiciatis provident quisquam sunt. Ad eaque quibusdam voluptas! Amet autem blanditiis cupiditate
         dolores in nulla, omnis praesentium.</p>
    </div>
<!-- (2) If you want to use slide indicators you need to add your indicator element 
     and mark it as indicator with *ffCarouselIndicator directive. -->
  <div *ffCarouselIndicator class="indicator">*</div>
<!-- (3) Also if you want to use arrows - just add RIGHT arrow element and mark it with *ffCarouselArrow directive-->
  <div *ffCarouselArrow class="arrow"> ></div>
</ff-carousel>

API

Selector: ff-carousel
Exported as: FFCarousel

Properties

  @Input() activeId: number = 0;

The activeId attribute set current slide by ID. To set third slide as active use:

  @Input() interval: number = 3000;

The interval attribute binding the time in milliseconds before slide change

  @Input() autoplay: boolean = true;

If autoplay is false slider will not switch slides

  @Input() pauseOnHover: boolean = true;

If pauseOnHover is true slider will not switch slides while mouse over the slider

  @Input() keyboard: boolean = true;

If keyboard is true allows switch slides using keyboard 'arrow left' and 'arrow right'.

  @Input() loop: boolean = true;

If loop is true allows switch slides from last slide to first slide.

  @Input() showArrows: boolean = true;

If showArrows is true - will show arrows (buttons 'next' and 'previous')

  @Input() showIndicators: boolean = false;

If showIndicators is true - will show slides indicators (slider navigation)

  @Input() btnOverlay: boolean = false;

If btnOverlay is true will wrap arrows (next and prev) with overlay

  @Output() switched: EventEmitter<number>;

Event triggered when slide was switched and send current active slide ID

Methods

  next: ()=>: number; 

You can call this method to show next slide. Method returns active slide ID after switched.

  prev: ()=>: number; 

You can call this method to show previous slide. Method returns active slide ID after switched.

  setActive: (id: number)=>: void; 

For set active slide by ID. E.g from external navigation.

  stop: ()=>: void; 
  play: ()=>: void; 

stop and play methods are responsible for autoplay.

Example

app.component.html

<ff-carousel [btnOverlay]="true" (switched)="switched()" #myCarousel="FFCarousel">
  <ng-container *ngFor="let img of images">
    <div *ffCarouselItem class="imgWrapper">
      <img src="{{img}}" alt="">
    </div>
  </ng-container>
  <div *ffCarouselIndicator class="indicator">*</div>
  <div *ffCarouselArrow class="arrow"> ></div>
</ff-carousel>

<button (click)="myCarousel.prev()">Some external 'prev' button</button>
<button (click)="myCarousel.next()">Some external 'next' button</button>

app.component.css

.imgWrapper {
  padding-top: 55%;
}

img {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
}

.indicator {
  color: white;
}
.arrow{
  font-size: 30px;
  color: #fff;
}

app.component.ts

import {Component} from '@angular/core';

@Component({
  selector: 'ff-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  images = [1, 2, 3, 4, 5, 6, 7].map(() => `https://picsum.photos/900/500?random&t=${Math.random()}`);

  switched(id:number) {
    console.log(`Switched! Current slide is ${id}`);
  }
}

License

MIT © Frontend Freelancer

8.1.9

4 years ago

8.1.8

4 years ago

8.1.6

4 years ago

8.1.5

5 years ago

8.1.4

5 years ago

8.1.3

5 years ago

8.1.2

5 years ago

8.1.1

5 years ago

8.1.0-a

5 years ago

8.1.0

5 years ago

8.0.6

5 years ago

8.0.5

5 years ago

8.0.4-a

5 years ago

8.0.4

5 years ago

8.0.3

5 years ago

8.0.2

5 years ago

8.0.1

5 years ago

0.4.5

6 years ago

0.4.4

6 years ago

0.4.3

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.1.23

6 years ago

0.1.22

6 years ago

0.1.21

6 years ago

0.1.20

6 years ago

0.1.19

6 years ago

0.1.18

6 years ago

0.1.17

6 years ago

0.1.16

6 years ago

0.1.15

6 years ago

0.1.14

6 years ago

0.1.13

6 years ago

0.1.12

6 years ago

0.1.11

6 years ago

0.1.10

6 years ago

0.1.8

6 years ago

0.1.9

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago