@@ -18,21 +18,35 @@ function addClassToDivsWithPicture() {
18
18
} ) ;
19
19
}
20
20
21
+ function addClassToDivsWithText ( ) {
22
+ const cloudImageElementsWithText = document . querySelectorAll ( '.cloud-image-text' ) ;
23
+ cloudImageElementsWithText . forEach ( ( cloudImageText ) => {
24
+ const childDivs = cloudImageText . querySelectorAll ( ':scope > div' ) ;
25
+
26
+ childDivs . forEach ( ( div ) => {
27
+ if ( ! div . querySelector ( 'picture' ) ) {
28
+ div . classList . add ( 'cloud-image-text-element' ) ;
29
+ }
30
+ } ) ;
31
+ } ) ;
32
+ }
33
+
21
34
function setDataAttributes ( ) {
22
35
// Arrays for top and left values calculation (mocked from the original site that seems random)
23
36
const topValues = [
24
37
20 , 0 , 50 , 70 , 100 , 60 , 90 , 20 , 0 , 40 ,
25
- 90 , 80 , 60 , 60 , 90 , 10 , 40 , 50 , 80 ,
38
+ 90 , 80 , 60 , 60 , 90 , 10 , 40 , 50 , 80 , 100 ,
26
39
] ;
27
40
const leftValues = [
28
- 50 , 90 , 60 , 80 , 30 , 80 , 0 , 20 , 60 , 90 ,
41
+ 50 , 90 , 60 , 80 , 30 , 80 , 0 , 20 , 60 , 90 , 100 ,
29
42
10 , 70 , 100 , 30 , 90 , 0 , 50 , 90 , 90 , 30 ,
30
43
] ;
31
44
const delayValues = [
32
45
4 , 5 , 2 , 34 , 3 , 7 , 8 ,
33
46
9 , 15 , 15 , 12 , 22 , 20 , 26 , 33 , 31 , 25 , 27 ,
34
47
] ;
35
48
const cloudImagePictureElements = document . querySelectorAll ( '.cloud-image-element' ) ;
49
+ const cloudImageTextElements = document . querySelectorAll ( '.cloud-image-text-element' ) ;
36
50
37
51
cloudImagePictureElements . forEach ( ( div , index ) => {
38
52
const leftIndex = index % leftValues . length ;
@@ -42,23 +56,41 @@ function setDataAttributes() {
42
56
div . setAttribute ( 'data-top' , topValues [ topIndex ] ) ;
43
57
div . setAttribute ( 'data-delay' , delayValues [ delayIndex ] ) ;
44
58
} ) ;
59
+
60
+ cloudImageTextElements . forEach ( ( div , index ) => {
61
+ const leftIndex = index % leftValues . length ;
62
+ const topIndex = index % topValues . length ;
63
+ const delayIndex = index % delayValues . length ;
64
+ div . setAttribute ( 'data-left' , leftValues [ leftIndex ] ) ;
65
+ div . setAttribute ( 'data-top' , topValues [ topIndex ] ) ;
66
+ div . setAttribute ( 'data-delay' , delayValues [ delayIndex ] ) ;
67
+ } ) ;
45
68
}
46
69
47
70
function positionImageInTheCloud ( ) {
48
71
const cloudImgContainer = document . querySelector ( '.cloud-image-wrapper' ) ;
49
72
const cloudImagePictureElements = document . querySelectorAll ( '.cloud-image-element' ) ;
73
+ const cloudImageTextElements = document . querySelectorAll ( '.cloud-image-text-element' ) ;
50
74
51
75
const {
52
- width : containerWidth ,
53
- height : containerHeight ,
76
+ width : ImgContainerWidth ,
77
+ height : ImgContainerHeight ,
54
78
} = cloudImgContainer . getBoundingClientRect ( ) ;
55
79
56
80
cloudImagePictureElements . forEach ( ( element ) => {
57
81
const img = element . querySelector ( 'img' ) ;
58
82
if ( ! img ) return ;
59
83
const { width : imgWidth , height : imgHeight } = img ;
60
- const elementStyleTop = `${ element . dataset . left * ( 1 - imgWidth / containerWidth ) } ` ;
61
- const elementStyleLeft = `${ element . dataset . top * ( 1 - imgHeight / containerHeight ) * 0.96 } ` ;
84
+ const elementStyleTop = `${ element . dataset . left * ( 1 - imgWidth / ImgContainerWidth ) } ` ;
85
+ const elementStyleLeft = `${ element . dataset . top * ( 1 - imgHeight / ImgContainerHeight ) * 0.96 } ` ;
86
+ element . style . left = ( elementStyleLeft > 60 ) ? `${ 60 } %` : `${ elementStyleLeft } %` ;
87
+ element . style . top = ( elementStyleTop > 57 ) ? `${ 57 } %` : `${ elementStyleTop } %` ;
88
+ element . style . animationDelay = `${ element . dataset . delay - 36 } s` ;
89
+ } ) ;
90
+
91
+ cloudImageTextElements . forEach ( ( element ) => {
92
+ const elementStyleTop = `${ 100 - element . dataset . left } ` ;
93
+ const elementStyleLeft = `${ 100 - element . dataset . top } ` ;
62
94
element . style . left = ( elementStyleLeft > 60 ) ? `${ 60 } %` : `${ elementStyleLeft } %` ;
63
95
element . style . top = ( elementStyleTop > 57 ) ? `${ 57 } %` : `${ elementStyleTop } %` ;
64
96
element . style . animationDelay = `${ element . dataset . delay - 36 } s` ;
@@ -68,4 +100,5 @@ function positionImageInTheCloud() {
68
100
export default positionImageInTheCloud ;
69
101
70
102
addClassToDivsWithPicture ( ) ;
103
+ addClassToDivsWithText ( ) ;
71
104
setDataAttributes ( ) ;
0 commit comments