Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ati
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
amal
ati
Commits
569642f4
Commit
569642f4
authored
Sep 26, 2019
by
Adarsh K
Browse files
Options
Browse Files
Download
Plain Diff
changes
parents
e2f2856a
a5b5e94b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
26 deletions
+26
-26
carousel.component.ts
src/app/home/carousel/carousel.component.ts
+16
-18
carousel.html
src/app/home/carousel/carousel.html
+5
-5
carousel.scss
src/app/home/carousel/carousel.scss
+2
-0
offers.component.ts
src/app/home/offers/offers.component.ts
+3
-3
No files found.
src/app/home/carousel/carousel.component.ts
View file @
569642f4
// tslint:disable-next-line:max-line-length
import
{
AfterViewInit
,
Component
,
ContentChildren
,
Directive
,
ElementRef
,
Input
,
OnInit
,
QueryList
,
TemplateRef
,
ViewChild
,
ViewChildren
}
from
'@angular/core'
;
import
{
AfterViewInit
,
Component
,
ContentChildren
,
Directive
,
ElementRef
,
Input
,
OnInit
,
QueryList
,
TemplateRef
,
ViewChild
,
ViewChildren
,
HostListener
}
from
'@angular/core'
;
import
{
CarouselDirective
}
from
'./../../directives/carousel.directive'
;
import
{
animate
,
AnimationBuilder
,
AnimationFactory
,
AnimationPlayer
,
style
}
from
'@angular/animations'
;
...
...
@@ -8,7 +8,7 @@ import { animate, AnimationBuilder, AnimationFactory, AnimationPlayer, style } f
})
export
class
CarouselItemElement
{
}
@
HostListener
(
'window:resize'
,
[
'$event'
])
@
Component
({
selector
:
'carousel'
,
exportAs
:
'carousel'
,
...
...
@@ -19,7 +19,7 @@ export class CarouselComponent implements AfterViewInit {
@
ContentChildren
(
CarouselDirective
)
items
:
QueryList
<
CarouselDirective
>
;
@
ViewChildren
(
CarouselItemElement
,
{
read
:
ElementRef
})
private
itemsElements
:
QueryList
<
ElementRef
>
;
@
ViewChild
(
'carousel'
,
{
static
:
false
})
private
carousel
:
ElementRef
;
@
Input
()
timing
=
'
2
50ms ease-in'
;
@
Input
()
timing
=
'
7
50ms ease-in'
;
@
Input
()
showControls
=
true
;
private
player
:
AnimationPlayer
;
private
itemWidth
:
number
;
...
...
@@ -27,7 +27,9 @@ export class CarouselComponent implements AfterViewInit {
carouselWrapperStyle
=
{};
next
()
{
if
(
this
.
currentSlide
+
1
===
this
.
items
.
length
)
return
;
if
(
this
.
currentSlide
+
1
===
this
.
items
.
length
)
{
this
.
currentSlide
=
-
1
;
}
this
.
currentSlide
=
(
this
.
currentSlide
+
1
)
%
this
.
items
.
length
;
const
offset
=
this
.
currentSlide
*
this
.
itemWidth
;
const
myAnimation
:
AnimationFactory
=
this
.
buildAnimation
(
offset
);
...
...
@@ -41,30 +43,26 @@ export class CarouselComponent implements AfterViewInit {
]);
}
prev
()
{
if
(
this
.
currentSlide
===
0
)
return
;
this
.
currentSlide
=
((
this
.
currentSlide
-
1
)
+
this
.
items
.
length
)
%
this
.
items
.
length
;
const
offset
=
this
.
currentSlide
*
this
.
itemWidth
;
const
myAnimation
:
AnimationFactory
=
this
.
buildAnimation
(
offset
);
this
.
player
=
myAnimation
.
create
(
this
.
carousel
.
nativeElement
);
this
.
player
.
play
();
}
constructor
(
private
builder
:
AnimationBuilder
)
{
console
.
log
(
this
.
items
)
;
this
.
itemWidth
=
window
.
innerWidth
;
}
ngAfterViewInit
()
{
// For some reason only here I need to add setTimeout, in my local env it's working without this.
setTimeout
(()
=>
{
this
.
itemWidth
=
this
.
itemsElements
.
first
.
nativeElement
.
getBoundingClientRect
().
width
;
// this.itemWidth = this.itemsElements.first.nativeElement.getBoundingClientRect().width;
this
.
itemWidth
=
window
.
innerHeight
;
console
.
log
(
this
.
itemWidth
);
this
.
carouselWrapperStyle
=
{
width
:
`
${
this
.
itemWidth
}
px`
}
}
;
});
setInterval
(()
=>
{
this
.
itemWidth
=
window
.
innerWidth
;
this
.
next
();
},
3000
);
}
}
src/app/home/carousel/carousel.html
View file @
569642f4
<section
class=
"carousel-wrapper"
[
ngStyle
]="
carouselWrapperStyle
"
>
<ul
class=
"carousel-inner"
#
carousel
>
<li
*
ngFor=
"let item of items;"
class=
"carousel-item"
>
<ul
class=
"carousel-inner"
#
carousel
>
<li
*
ngFor=
"let item of items;"
class=
"carousel-item"
[
ngStyle
]="{'
width
.
px
'
:itemWidth
}"
>
<ng-container
[
ngTemplateOutlet
]="
item
.
tpl
"
></ng-container>
</li>
</ul>
</section>
<div
*
ngIf=
"showControls"
style=
"margin-top: 1em"
>
<
!-- <
div *ngIf="showControls" style="margin-top: 1em">
<button (click)="next()" class="btn btn-default">Next</button>
<button (click)="prev()" class="btn btn-default">Prev</button>
</div>
\ No newline at end of file
</div> -->
\ No newline at end of file
src/app/home/carousel/carousel.scss
View file @
569642f4
...
...
@@ -11,4 +11,5 @@
.carousel-inner
{
display
:
flex
;
width
:
max-content
;
}
\ No newline at end of file
src/app/home/offers/offers.component.ts
View file @
569642f4
...
...
@@ -11,9 +11,9 @@ export class OffersComponent {
ngOnInit
()
{
this
.
items
=
[
{
title
:
'Airfares starting at Rs.
899*'
,
desc
:
'Flights, 1080 Hotels, 410 Homestays,<br> Holiday Packages get 1080 Hotels, 410 Homestays
..'
,
code
:
'AT 500'
},
{
title
:
'Airfares starting at Rs.
899*'
,
desc
:
'Flights, 1080 Hotels, 410 Homestays,<br> Holiday Packages get 1080 Hotels, 410 Homestays
..'
,
code
:
'AT 500'
},
{
title
:
'Airfares starting at Rs. 899*'
,
desc
:
'Flights, 1080 Hotels, 410 Homestays,<br> Holiday Packages get 1080 Hotels, 410 Home
stays
..'
,
code
:
'AT 500'
},
{
title
:
'Airfares starting at Rs.
399*'
,
desc
:
'Flights, 1080 Hotels, 410 Homestays,<br> Holiday Packages get 1080 Hotels, 410 Home
..'
,
code
:
'AT 500'
},
{
title
:
'Airfares starting at Rs.
599*'
,
desc
:
'Flights, 1080 Hotels, 410 Homestays,<br> Holiday Packages get 1080 Hotels, 410 Home
..'
,
code
:
'AT 500'
},
{
title
:
'Airfares starting at Rs. 899*'
,
desc
:
'Flights, 1080 Hotels, 410 Homestays,<br> Holiday Packages get 1080 Hotels, 410 Home..'
,
code
:
'AT 500'
},
]
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment