1
1
import { Component , ViewChild } from '@angular/core' ;
2
- import { AlertController , NavController , Slides , IonicPage } from 'ionic-angular' ;
2
+ import { NavController , Slides , IonicPage } from 'ionic-angular' ;
3
3
4
4
@IonicPage ( )
5
5
@Component ( {
@@ -9,79 +9,43 @@ import { AlertController, NavController, Slides, IonicPage } from 'ionic-angular
9
9
export class SlideColorChangingPage {
10
10
@ViewChild ( 'slider' ) slider : Slides ;
11
11
12
- slideOptions = {
13
- pager : true ,
14
- } ;
15
-
16
- slides = [ {
17
- title : "Dream's Adventure" ,
18
- imageUrl : "assets/img/lists/wishlist-1.jpg" ,
19
- songs : 2 ,
20
- private : false
21
- } ,
22
- {
23
- title : "For the Weekend" ,
24
- imageUrl : "assets/img/lists/wishlist-2.jpg" ,
25
- songs : 4 ,
26
- private : false
27
- } ,
28
- {
29
- title : "Family Time" ,
30
- imageUrl : "assets/img/lists/wishlist-3.jpg" ,
31
- songs : 5 ,
32
- private : true
33
- } ,
34
- {
35
- title : "My Trip" ,
36
- imageUrl : "assets/img/lists/wishlist-4.jpg" ,
37
- songs : 12 ,
38
- private : true
39
- }
12
+ slides = [
13
+ {
14
+ title : "Dream's Adventure" ,
15
+ imageUrl : "assets/img/lists/wishlist-1.jpg" ,
16
+ songs : 2 ,
17
+ private : false
18
+ } ,
19
+ {
20
+ title : "For the Weekend" ,
21
+ imageUrl : "assets/img/lists/wishlist-2.jpg" ,
22
+ songs : 4 ,
23
+ private : false
24
+ } ,
25
+ {
26
+ title : "Family Time" ,
27
+ imageUrl : "assets/img/lists/wishlist-3.jpg" ,
28
+ songs : 5 ,
29
+ private : true
30
+ } ,
31
+ {
32
+ title : "My Trip" ,
33
+ imageUrl : "assets/img/lists/wishlist-4.jpg" ,
34
+ songs : 12 ,
35
+ private : true
36
+ }
40
37
]
41
38
39
+ color : any ;
40
+ colors = [ '#e43737' , '#e0e437' , '#37e446' , '#375be4' , '#972cb1' ]
41
+
42
42
onSlideChanged ( ) {
43
43
let currentIndex = this . slider . getActiveIndex ( ) ;
44
+ this . color = this . colors [ currentIndex ] ;
44
45
console . log ( "Slide changed! Current index is" , currentIndex ) ;
45
46
}
46
47
47
- constructor ( public navCtrl : NavController , public alertCtrl : AlertController ) {
48
- }
49
-
50
- decimalToHex ( d , padding ) {
51
- var hex = Number ( d ) . toString ( 16 ) ;
52
- padding = typeof ( padding ) === "undefined" || padding === null ? padding = 2 : padding ;
53
-
54
- while ( hex . length < padding ) {
55
- hex = "0" + hex ;
56
- }
57
-
58
- return hex ;
59
- }
60
-
61
- color : any ;
62
- onSlideMove ( event ) {
63
- console . log ( event ) ;
64
- let maxValue = event . virtualSize - event . width ;
65
- let normalizedValue = this . normalize ( event . translate * - 1 , maxValue ) ;
66
- let hexCode = this . decimalToHex ( normalizedValue , 2 ) ;
67
- // let slideCount = event.slidesGrid.length;
68
- let inverseHexCode = this . decimalToHex ( 255 - normalizedValue , 2 ) ;
69
- if ( event . activeIndex == 0 ) {
70
- this . color = '#' + inverseHexCode + hexCode + hexCode ;
71
- } else if ( event . activeIndex == 1 ) {
72
- this . color = '#' + hexCode + inverseHexCode + hexCode ;
73
- } if ( event . activeIndex == 2 ) {
74
- this . color = '#' + hexCode + hexCode + inverseHexCode ;
75
- } else {
76
- this . color = '#' + hexCode + hexCode + hexCode ;
77
- }
78
- }
79
-
80
- normalize ( value , maxValue ) {
81
- value = value < 0 ? 0 : value ;
82
- let proportion = value / maxValue ;
83
- console . log ( value , proportion ) ;
84
- proportion = proportion > 1 ? 1 : proportion ;
85
- return Math . trunc ( proportion * 255 ) ;
48
+ constructor ( public navCtrl : NavController ) {
49
+ this . color = this . colors [ 0 ] ;
86
50
}
87
51
}
0 commit comments