Skip to content

Commit 890ea42

Browse files
committed
fixing issue
1 parent d479891 commit 890ea42

6 files changed

Lines changed: 53 additions & 70 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
<app-slider></app-slider>
12
<app-product></app-product>

src/app/all-products/all-products.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Component } from '@angular/core';
22
import { ProductComponent } from '../product/product.component';
3+
import { SliderComponent } from '../slider/slider.component';
34

45

56
@Component({
67
selector: 'app-all-products',
7-
imports: [ProductComponent],
8+
imports: [ProductComponent,SliderComponent],
89
templateUrl: './all-products.component.html',
910
styleUrl: './all-products.component.scss'
1011
})

src/app/home/home.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<app-feature-product></app-feature-product>
2+
<app-slider></app-slider>
23
<app-category></app-category>
3-
<app-slider></app-slider>

src/app/slider/slider.component.html

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,3 @@
77
<button class="btn btn-primary position-absolute start-0" (click)="prev()"></button>
88
<button class="btn btn-primary position-absolute end-0" (click)="next()"></button>
99
</div>
10-
<style>
11-
.slider-container {
12-
width: 100%;
13-
height: 300px;
14-
position: relative;
15-
}
16-
.slider-track {
17-
transition: transform 0.5s ease-in-out;
18-
}
19-
.slide {
20-
min-width: 100%;
21-
height: 100%;
22-
flex-shrink: 0;
23-
}
24-
25-
.slide img {
26-
width: 100%;
27-
height: 100%;
28-
object-fit: cover;
29-
}
30-
</style>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.slider-container {
2+
width: 100%;
3+
height: 300px;
4+
position: relative;
5+
}
6+
7+
.slider-track {
8+
transition: transform 0.5s ease-in-out;
9+
}
10+
11+
.slide {
12+
min-width: 100%;
13+
height: 100%;
14+
flex-shrink: 0;
15+
16+
img {
17+
width: 100%;
18+
height: 100%;
19+
object-fit: cover;
20+
}
21+
}

src/app/slider/slider.component.ts

Lines changed: 28 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,47 @@
11
import { CommonModule } from '@angular/common';
2-
import { Component } from '@angular/core';
2+
import { Component} from '@angular/core';
33

44
@Component({
55
selector: 'app-slider',
66
standalone: true,
77
imports: [CommonModule],
88
templateUrl: './slider.component.html',
9-
styleUrl: './slider.component.scss'
9+
styleUrls: ['./slider.component.scss']
1010
})
11-
export class SliderComponent {
12-
images: string[] =
11+
export class SliderComponent{
12+
images: string[] =
1313
[
1414
'Assets/slider1.jpg',
1515
'Assets/slider2.jpg',
1616
'Assets/slider3.jpg',
1717
]
18-
currentIndex: number = 0;
19-
autoSliderInterval!: number;
20-
21-
ngOnInit(): void
22-
{
23-
this.startAutoSlider();
18+
currentIndex: number = 0;
19+
getTransform(): string {
20+
return `translateX(-${this.currentIndex * 100}%)`;
21+
}
22+
next(): void {
23+
if (this.currentIndex < this.images.length - 1) {
24+
this.currentIndex++;
2425
}
25-
26-
getTransform(): string
27-
{
28-
return `translateX(-${this.currentIndex * 100}%)`;
26+
else {
27+
this.reset();
2928
}
30-
next(): void
31-
{
32-
if (this.currentIndex < this.images.length - 1){
33-
this.currentIndex++;
34-
}
35-
else
36-
{
37-
this.reset();
38-
}
29+
}
30+
prev(): void {
31+
if (this.currentIndex > 0) {
32+
this.currentIndex--;
3933
}
40-
prev(): void
41-
{
42-
if (this.currentIndex > 0){
43-
this.currentIndex--;
44-
}
45-
else
46-
{
47-
this.reset();
48-
}
34+
else {
35+
this.reset();
4936
}
50-
reset(): void
51-
{
52-
if (this.currentIndex === 0) {
53-
this.currentIndex = this.images.length - 1;
54-
}
55-
else
56-
{
57-
this.currentIndex = 0;
58-
}
37+
}
38+
reset(): void {
39+
if (this.currentIndex === 0) {
40+
this.currentIndex = this.images.length - 1;
5941
}
60-
startAutoSlider(): void
61-
{
62-
this.autoSliderInterval = window.setInterval(() => {
63-
this.next();
64-
}, 2000); // Change slide every 2 seconds
42+
else {
43+
this.currentIndex = 0;
6544
}
66-
}
45+
}
46+
}
47+

0 commit comments

Comments
 (0)