|
|
@ -19,6 +19,9 @@ export class HomeComponent implements OnInit { |
|
|
|
public paused: boolean = false |
|
|
|
private scrollPos: number = 0 |
|
|
|
|
|
|
|
private swipeCoord?: [number, number] |
|
|
|
private swipeTime?: number |
|
|
|
|
|
|
|
constructor( |
|
|
|
private apisService: ApisService, |
|
|
|
private router: Router, |
|
|
@ -69,9 +72,9 @@ export class HomeComponent implements OnInit { |
|
|
|
},2000) |
|
|
|
} |
|
|
|
|
|
|
|
showDetails(id): void { |
|
|
|
showDetails(id, title = ''): void { |
|
|
|
const section = this.section == 'exhibitions' ? 'exhibitions' : 'works' |
|
|
|
this.router.navigate([`/detail/${section}/${id}`]) |
|
|
|
this.router.navigate([`/detail/${section}/${id}/${title.toLowerCase().replace(/[^a-zA-Z0-9]/g, '_')}`]) |
|
|
|
} |
|
|
|
|
|
|
|
onLoad(id): void { |
|
|
@ -95,4 +98,36 @@ export class HomeComponent implements OnInit { |
|
|
|
this.scrollContent.nativeElement.style.marginLeft = this.scrollPos + 'px' |
|
|
|
} |
|
|
|
|
|
|
|
swipe(e: TouchEvent, when: string): void { |
|
|
|
const coord: [number, number] = [e.changedTouches[0].clientX, e.changedTouches[0].clientY] |
|
|
|
const time = new Date().getTime() |
|
|
|
const scrollWidth = document.body.clientWidth |
|
|
|
const scrollPos = parseInt(this.scrollContent.nativeElement.style.marginLeft) || 0 |
|
|
|
|
|
|
|
this.paused = true |
|
|
|
|
|
|
|
if (when === 'start') { |
|
|
|
this.swipeCoord = coord |
|
|
|
this.swipeTime = time |
|
|
|
} else if (when === 'end') { |
|
|
|
const direction = [coord[0] - this.swipeCoord[0], coord[1] - this.swipeCoord[1]] |
|
|
|
const duration = time - this.swipeTime |
|
|
|
|
|
|
|
if (duration < 1000 |
|
|
|
&& Math.abs(direction[0]) > 30 |
|
|
|
&& Math.abs(direction[0]) > Math.abs(direction[1] * 3)) { |
|
|
|
const swipe = direction[0] < 0 ? 'next' : 'prev' |
|
|
|
switch(swipe) { |
|
|
|
case 'prev': |
|
|
|
this.scrollPos = scrollPos + scrollWidth >= 0 ? 0 : scrollPos + scrollWidth |
|
|
|
break; |
|
|
|
case 'next': |
|
|
|
this.scrollPos = scrollPos - scrollWidth <= -(this.scrollContent.nativeElement.offsetWidth - document.body.clientWidth) ? |
|
|
|
-(this.scrollContent.nativeElement.offsetWidth - document.body.clientWidth) : scrollPos - scrollWidth |
|
|
|
break; |
|
|
|
} |
|
|
|
this.scrollContent.nativeElement.style.marginLeft = this.scrollPos + 'px' |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|