File tree Expand file tree Collapse file tree 3 files changed +9
-10
lines changed Expand file tree Collapse file tree 3 files changed +9
-10
lines changed Original file line number Diff line number Diff line change 1
- <!DOCTYPE html>
1
+ <!-- intentionally leaving out the <! DOCTYPE html> -- >
2
2
< html lang ="en ">
3
3
< head >
4
4
< title > Open: scroll (via embed code)</ title >
@@ -59,7 +59,7 @@ <h2>Customize the percentage</h2>
59
59
const offsetTop = window . pageYOffset || document . documentElement . scrollTop
60
60
const clientTop = document . documentElement . clientTop || 0
61
61
const scrollTopPixels = offsetTop - clientTop
62
- const scrollTopPercentage = scrollTopPixels / document . body . clientHeight * 100
62
+ const scrollTopPercentage = scrollTopPixels / document . documentElement . clientHeight * 100
63
63
document . getElementById ( 'scroll-pixels' ) . innerHTML = scrollTopPixels ;
64
64
document . getElementById ( 'scroll-percentage' ) . innerHTML = ( Math . round ( scrollTopPercentage * 100 ) / 100 ) . toFixed ( 2 ) ;
65
65
} )
Original file line number Diff line number Diff line change @@ -18,9 +18,10 @@ const openOnScroll = (popup, scrollThreshold) => {
18
18
const offsetTop = window . pageYOffset || document . documentElement . scrollTop
19
19
const clientTop = document . documentElement . clientTop || 0
20
20
const scrollTopPixels = offsetTop - clientTop
21
- const scrollTopPercentage = scrollTopPixels / document . body . clientHeight * 100
22
- const viewportHeight = Math . max ( document . documentElement . clientHeight || 0 , window . innerHeight || 0 )
23
- if ( scrollTopPercentage >= scrollThreshold || scrollTopPixels + viewportHeight >= document . body . clientHeight ) {
21
+ const scrollTopPercentage = scrollTopPixels / document . documentElement . clientHeight * 100
22
+ const scrolledToTheBottom = scrollTopPixels + window . innerHeight >= document . documentElement . clientHeight
23
+
24
+ if ( scrollTopPercentage >= scrollThreshold || scrolledToTheBottom ) {
24
25
popup . open ( )
25
26
document . removeEventListener ( 'scroll' , handleScroll )
26
27
}
Original file line number Diff line number Diff line change @@ -88,19 +88,17 @@ describe('handleAutoOpen', () => {
88
88
89
89
beforeAll ( ( ) => {
90
90
global . document = {
91
- body : {
92
- clientHeight : 1000
93
- } ,
94
91
documentElement : {
95
- clientHeight : 500
92
+ clientHeight : 1000
96
93
} ,
97
94
addEventListener : ( _event , fn ) => {
98
95
handler = fn
99
96
} ,
100
97
removeEventListener
101
98
}
102
99
global . window = {
103
- pageYOffset : 0
100
+ pageYOffset : 0 ,
101
+ innerHeight : 500
104
102
}
105
103
} )
106
104
You can’t perform that action at this time.
0 commit comments