@@ -6,11 +6,13 @@ Angular Universal carousel
66
77## changelog [ ![ NPM version] ( https://badge.fury.io/js/ngu-carousel.png )] ( http://badge.fury.io/js/ngu-carousel )
88
9- for ChangeLog go to [ releases ] ( https://github.com/sheikalthaf/ngu-carousel/releases )
9+ for ChangeLog go to [ CHANGELOG.md ] ( https://github.com/sheikalthaf/ngu-carousel/blob/master/CHANGELOG.md )
1010
1111## Demo
1212
13- SSR Demo available [ Here] ( https://ngu-carousel.firebaseapp.com )
13+ Demo available in Stackblitz [ Here] ( https://stackblitz.com/edit/ngu-carousel-ng6 )
14+
15+ Demo available [ Here] ( https://ngu-carousel.firebaseapp.com )
1416
1517## Installation
1618
@@ -40,56 +42,87 @@ import 'hammerjs';
4042Then use in your component:
4143
4244``` javascript
43- import { Component } from ' @angular/core' ;
44- import { NguCarousel } from ' @ngu/carousel' ;
45+ import { Component , OnInit } from ' @angular/core' ;
46+ import { NguCarouselConfig } from ' @ngu/carousel' ;
4547
4648@Component ({
4749 selector: ' sample' ,
4850 template: `
49- <ngu-carousel
50- [inputs]="carouselOne"
51- (carouselLoad)="myfunc($event)">
52- <ngu-item NguCarouselItem>
53- ....
54- </ngu-item>
55- <ngu-item NguCarouselItem>
56- ....
57- </ngu-item>
58- <ngu-item NguCarouselItem>
59- ....
60- </ngu-item>
61- <button NguCarouselPrev class='leftRs'><</button>
62- <button NguCarouselNext class='rightRs'>></button>
51+ <ngu-carousel #myCarousel [inputs]="carouselTile" [dataSource]="carouselTileItems">
52+ <ngu-tile *nguCarouselDef="let item; let i = index">
53+
54+ <ngu-carousel #myCarousel [inputs]="carouselTile" (carouselLoad)="carouselTileLoad(i)" [dataSource]="carouselTiles[i]">
55+ <ngu-tile *nguCarouselDef="let item; let j = index">
56+ <div class="tile" [style.background]="'url(' + item + ')'" style="min-height: 200px">
57+ <h1>{{j}}</h1>
58+ </div>
59+ </ngu-tile>
60+ <button NguCarouselPrev class="leftRs" [style.opacity]="myCarousel.isFirst ? 0.5:1"><</button>
61+ <button NguCarouselNext class="rightRs" [style.opacity]="myCarousel.isLast ? 0.5:1">></button>
62+ <ul class="myPoint" NguCarouselPoint>
63+ <li *ngFor="let j of myCarousel.pointNumbers; let j = index" [class.active]="j==myCarousel.activePoint" (click)="myCarousel.moveTo(j)"
64+ [style.background]="'url(' + carouselTileItems[j] + ')'"></li>
65+ </ul>
6366 </ngu-carousel>
67+
68+ </ngu-tile>
69+ <button NguCarouselPrev class="leftRs" [style.opacity]="myCarousel.isFirst ? 0.5:1"><</button>
70+ <button NguCarouselNext class="rightRs" [style.opacity]="myCarousel.isLast ? 0.5:1">></button>
71+ <ul class="myPoint" NguCarouselPoint>
72+ <li *ngFor="let i of myCarousel.pointNumbers; let i = index" [class.active]="i==myCarousel.activePoint" (click)="myCarousel.moveTo(i)"
73+ [style.background]="'url(' + carouselTileItems[i] + ')'"></li>
74+ </ul>
75+ </ngu-carousel>
76+
6477 ` ,
6578})
6679export class SampleComponent implements OnInit {
67-
68- public carouselOne: NguCarousel;
80+ imgags = [
81+ ' assets/bg.jpg' ,
82+ ' assets/car.png' ,
83+ ' assets/canberra.jpg' ,
84+ ' assets/holi.jpg'
85+ ];
86+ public carouselTileItems: Array < any> = [0 , 1 , 2 , 3 , 4 , 5 ];
87+ public carouselTiles = {
88+ 0 : [],
89+ 1 : [],
90+ 2 : [],
91+ 3 : [],
92+ 4 : [],
93+ 5 : []
94+ };
95+ public carouselTile: NguCarouselConfig = {
96+ grid: { xs: 1 , sm: 1 , md: 3 , lg: 3 , all: 0 },
97+ slide: 3 ,
98+ speed: 250 ,
99+ point: {
100+ visible: true
101+ },
102+ load: 2 ,
103+ velocity: 0 ,
104+ touch: true ,
105+ easing: ' cubic-bezier(0, 0, 0.2, 1)'
106+ };
107+ constructor () {}
69108
70109 ngOnInit () {
71- this .carouselOne = {
72- grid: {xs: 1 , sm: 1 , md: 1 , lg: 1 , all: 0 },
73- slide: 1 ,
74- speed: 400 ,
75- interval: 4000 ,
76- point: {
77- visible: true
78- },
79- load: 2 ,
80- touch: true ,
81- loop: true ,
82- custom: ' banner'
83- }
110+ this .carouselTileItems .forEach (el => {
111+ this .carouselTileLoad (el);
112+ });
84113 }
85114
86- public myfunc (event : Event ) {
87- // carouselLoad will trigger this funnction when your load value reaches
88- // it is helps to load the data by parts to increase the performance of the app
89- // must use feature to all carousel
115+ public carouselTileLoad (j ) {
116+ // console.log(this.carouselTiles[j]);
117+ const len = this .carouselTiles [j].length ;
118+ if (len <= 30 ) {
119+ for (let i = len; i < len + 15 ; i++ ) {
120+ this .carouselTiles [j].push (
121+ this .imgags [Math .floor (Math .random () * this .imgags .length )]
122+ );
123+ }
124+ }
90125 }
91-
92-
93126}
94127```
95128
@@ -141,11 +174,11 @@ export class Touch {
141174 velocity: number;
142175}
143176
144- export class NguCarousel {
177+ export class NguCarouselConfig {
145178 grid: Transfrom;
146179 slide?: number;
147180 speed?: number;
148- interval?: number ;
181+ interval?: CarouselInterval ;
149182 animation?: Animate;
150183 point?: Point ;
151184 type?: string;
@@ -155,7 +188,9 @@ export class NguCarousel {
155188 touch?: boolean;
156189 easing?: string;
157190 RTL ?: boolean;
191+ button?: NguButton;
158192 vertical?: Vertical;
193+ velocity?: number;
159194}
160195
161196export class Grid {
@@ -169,7 +204,6 @@ export class Grid {
169204export interface Point {
170205 visible : boolean ;
171206 hideOnSingleSlide ?: boolean ;
172- pointStyles ?: string ;
173207}
174208
175209export type Custom = ' banner' ;
@@ -184,7 +218,6 @@ export type Animate = 'lazy';
184218| ` interval ` | milli seconds | optional | It is used to make carousel auto slide with given value. interval defines the interval between slides |
185219| ` load ` | number | optional | is used to load the items similar to pagination. the carousel will tigger the carouslLoad function to load another set of items. it will help you to improve the performance of the app.** ` (carouselLoad)="myfunc($event)" ` ** |
186220| ` point.visible ` | boolean | optional | It is used to indicate no. of slides and also shows the current active slide. |
187- | ` point.pointStyle ` | string | optional | It is used to customize the point indicator. make sure your check the guide. |
188221| ` point.hideOnSingleSlide ` | boolean | optional | It is used to hide the point indicator when slide is less than one. |
189222| ` touch ` | boolean | optional | It is used to active touch support to the carousel. |
190223| ` easing ` | string | optional | It is used to define the easing style of the carousel. Only define the ease name without any timing like ` ease ` ,` ease-in ` |
@@ -208,28 +241,15 @@ This is HTML I'm using in the carousel. Add your own css according to this eleme
208241``` html
209242<ngu-carousel
210243 [inputs] =" carouselBanner"
211- (initData) =" initDataFn($event)"
212244 (onMove) =" onmoveFn($event)"
213245 (carouselLoad) =" loadItemsFn()" >
214246</ngu-carousel >
215247```
216248
217- - ` inputs ` is an ` Input ` and It accepts ` NguCarousel ` .
218- - ` initData ` is an ` Output ` which triggered on carousel init and it emits token to exchange with service to contol the carousel.
249+ - ` inputs ` is an ` Input ` and It accepts ` NguCarouselConfig ` .
219250- ` onMove ` is an ` Output ` which triggered on every slide before start and it will emit ` $event ` as ` NguCarouselStore ` object.
220251- ` carouselLoad ` is an ` Output ` which triggered when slide reaches the end on items based on inputs ` load ` .
221252
222- ## Carousel Service
223-
224- ``` javascript
225- import { NguCarouselService } from ' @ngu/carousel' ;
226- ```
227-
228- This carousel Service supports:
229-
230- - ` reset(token) ` - This function will reset the carousel
231- - ` moveToSlide(token, index, animate) ` - This function is used to move to index with animation control.
232-
233253# Getstarted guide
234254
235255## Banner with Custom point style
@@ -301,36 +321,12 @@ export class Sample implements OnInit {
301321 grid: { xs: 1 , sm: 1 , md: 1 , lg: 1 , all: 0 },
302322 slide: 1 ,
303323 speed: 400 ,
304- interval: 4000 ,
324+ interval: {
325+ timing: 3000 ,
326+ initialDelay: 1000
327+ },
305328 point: {
306- visible: true ,
307- pointStyles: `
308- .ngucarouselPoint {
309- list-style-type: none;
310- text-align: center;
311- padding: 12px;
312- margin: 0;
313- white-space: nowrap;
314- overflow: auto;
315- position: absolute;
316- width: 100%;
317- bottom: 20px;
318- left: 0;
319- box-sizing: border-box;
320- }
321- .ngucarouselPoint li {
322- display: inline-block;
323- border-radius: 999px;
324- background: rgba(255, 255, 255, 0.55);
325- padding: 5px;
326- margin: 0 3px;
327- transition: .4s ease all;
328- }
329- .ngucarouselPoint li.active {
330- background: white;
331- width: 10px;
332- }
333- `
329+ visible: true
334330 },
335331 load: 2 ,
336332 loop: true ,
@@ -349,7 +345,7 @@ export class Sample implements OnInit {
349345
350346``` javascript
351347import { Component } from ' @angular/core' ;
352- import { NguCarousel , NguCarouselStore } from ' @ngu/carousel' ;
348+ import { NguCarousel , NguCarouselConfig } from ' @ngu/carousel' ;
353349
354350@Component ({
355351 selector: ' app-carousel' ,
@@ -405,6 +401,32 @@ import { NguCarousel, NguCarouselStore } from '@ngu/carousel';
405401 border-radius: 999px;
406402 right: 0;
407403 }
404+
405+ .ngucarouselPoint {
406+ list-style-type: none;
407+ text-align: center;
408+ padding: 12px;
409+ margin: 0;
410+ white-space: nowrap;
411+ overflow: auto;
412+ position: absolute;
413+ width: 100%;
414+ bottom: 20px;
415+ left: 0;
416+ box-sizing: border-box;
417+ }
418+ .ngucarouselPoint li {
419+ display: inline-block;
420+ border-radius: 999px;
421+ background: rgba(255, 255, 255, 0.55);
422+ padding: 5px;
423+ margin: 0 3px;
424+ transition: .4s ease all;
425+ }
426+ .ngucarouselPoint li.active {
427+ background: white;
428+ width: 10px;
429+ }
408430 `
409431 ]
410432})
@@ -416,34 +438,7 @@ export class Sample implements OnInit {
416438 speed: 400 ,
417439 interval: 4000 ,
418440 point: {
419- visible: true ,
420- pointStyles: `
421- .ngucarouselPoint {
422- list-style-type: none;
423- text-align: center;
424- padding: 12px;
425- margin: 0;
426- white-space: nowrap;
427- overflow: auto;
428- position: absolute;
429- width: 100%;
430- bottom: 20px;
431- left: 0;
432- box-sizing: border-box;
433- }
434- .ngucarouselPoint li {
435- display: inline-block;
436- border-radius: 999px;
437- background: rgba(255, 255, 255, 0.55);
438- padding: 5px;
439- margin: 0 3px;
440- transition: .4s ease all;
441- }
442- .ngucarouselPoint li.active {
443- background: white;
444- width: 10px;
445- }
446- `
441+ visible: true
447442 },
448443 load: 2 ,
449444 loop: true ,
@@ -456,24 +451,23 @@ export class Sample implements OnInit {
456451 }
457452
458453 /* It will be triggered on every slide*/
459- onmoveFn (data : NguCarouselStore ) {
454+ onmoveFn (data : NguCarousel ) {
460455 console .log (data);
461456 }
462457}
463458```
464459
465- ## Tile with Service
460+ ## Tile with Carousel Control
466461
467462``` javascript
468463import { Component } from ' @angular/core' ;
469- import { NguCarousel , NguCarouselStore , NguCarouselService } from ' @ngu/carousel' ;
464+ import { NguCarousel , NguCarouselConfig } from ' @ngu/carousel' ;
470465
471466@Component ({
472467 selector: ' app-carousel' ,
473468 template: `
474- <ngu-carousel
469+ <ngu-carousel #carousel
475470 [inputs]="carouselTile"
476- (initData)="initDataFn($event)"
477471 (carouselLoad)="carouselTileLoad($event)">
478472
479473 <ngu-tile NguCarouselItem *ngFor="let Tile of carouselTileItems">
@@ -522,9 +516,10 @@ export class Sample implements OnInit {
522516 private carouselToken: string;
523517
524518 public carouselTileItems: Array < any> ;
525- public carouselTile: NguCarousel;
519+ public carouselTile: NguCarouselConfig;
520+ @ViewChild (' carousel' ) carousel: NguCarousel;
526521
527- constructor (private carousel : NguCarouselService ) { }
522+ constructor () { }
528523
529524 ngOnInit (){
530525 this .carouselTileItems = [0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 ];
0 commit comments