@@ -36,25 +36,21 @@ export function useIonHeaderParallax({
3636
3737 // ion-toolbar background
3838 const toolbarShadowRoot = toolbar . shadowRoot
39-
40- if ( ! toolbarShadowRoot ) return
41-
39+ if ( ! toolbarShadowRoot ) throw new Error ( 'No shadow' )
4240 const toolbarBackground = toolbarShadowRoot . querySelector ( '.toolbar-background' ) as HTMLElement
4341
44- if ( ! toolbarBackground ) return
42+ if ( ! toolbarBackground ) throw new Error ( 'No .toolbar-background' )
4543
4644 // ion-title
47- const ionTitle = toolbar . querySelector ( 'ion-title' ) as HTMLElement
45+ const ionTitle = toolbar . querySelector ( 'ion-title' )
4846
4947 // ion-buttons
5048 const barButtons = header . querySelector ( 'ion-buttons' ) as HTMLElement
5149
5250 // ion-content
53- const ionContent = parentElement . querySelector ( 'ion-content' ) as HTMLElement
54- if ( ! ionContent ) throw new Error ( 'Parallax an <ion-content> element on the page to work.' )
55-
51+ const ionContent = parentElement . querySelector ( 'ion-content' )
52+ if ( ! ionContent ) throw new Error ( 'Parallax requires an <ion-content> element on the page to work.' )
5653 const scrollContent = ionContent . shadowRoot ?. querySelector ( '.inner-scroll' ) as HTMLElement
57-
5854 if ( ! scrollContent ) {
5955 throw new Error ( 'Parallax directive requires an <ion-content> element on the page to work.' )
6056 }
@@ -71,6 +67,7 @@ export function useIonHeaderParallax({
7167
7268 if ( overlayTitle ) {
7369 overlayTitle . classList . add ( 'parallax-title' )
70+
7471 setTimeout ( ( ) => {
7572 if ( overlayTitle . shadowRoot ) {
7673 const toolbarTitle = overlayTitle . shadowRoot . querySelector ( '.toolbar-title' ) as HTMLElement
@@ -88,24 +85,19 @@ export function useIonHeaderParallax({
8885
8986 /*** initStyles ***/
9087 // still in init use JS DOM
91- let headerHeight = scrollContent ?. clientHeight
9288 setTicking ( false )
9389
9490 // fetch styles
9591 maximumHeight = parseFloat ( maximumHeight . toString ( ) )
9692 let headerMinHeight = toolbar . offsetHeight
9793
98- let scrollContentPaddingTop = 0
99-
100- if ( scrollContent ) {
101- scrollContentPaddingTop = parseFloat (
102- window . getComputedStyle ( scrollContent as Element , null ) . paddingTop . replace ( 'px' , '' )
103- )
104- }
105- let originalToolbarBgColor = 'white'
94+ let scrollContentPaddingTop : number = parseFloat (
95+ window . getComputedStyle ( scrollContent , null ) . paddingTop . replace ( 'px' , '' )
96+ )
10697
107- if ( toolbarBackground ) {
108- originalToolbarBgColor = window . getComputedStyle ( toolbarBackground as Element , null ) . backgroundColor
98+ const originalToolbarBgColor = window . getComputedStyle ( toolbarBackground , null ) . backgroundColor
99+ if ( ! originalToolbarBgColor ) {
100+ throw new Error ( 'Error: toolbarBackround is null.' )
109101 }
110102
111103 // header and title
@@ -139,9 +131,7 @@ export function useIonHeaderParallax({
139131 imageOverlay . style . backgroundPosition = 'center'
140132
141133 // .toolbar-background
142- if ( toolbarBackground ) {
143- toolbarBackground . style . backgroundColor = originalToolbarBgColor
144- }
134+ toolbarBackground . style . backgroundColor = originalToolbarBgColor
145135
146136 // .bar-buttons
147137 if ( barButtons ) {
@@ -160,14 +150,6 @@ export function useIonHeaderParallax({
160150 scrollContent . style . paddingTop = `${ maximumHeight + scrollContentPaddingTop - headerMinHeight } px`
161151 }
162152
163- /** init events */
164- window . addEventListener (
165- 'resize' ,
166- ( ) => {
167- headerHeight = scrollContent . clientHeight
168- } ,
169- false
170- )
171153
172154 if ( scrollContent ) {
173155 scrollContent . addEventListener ( 'scroll' , ( _e ) => {
@@ -176,15 +158,6 @@ export function useIonHeaderParallax({
176158 // to do
177159
178160 const scrollTop = scrollContent . scrollTop
179- let translateAmt : number
180- let scaleAmt : number
181- if ( scrollTop >= 0 ) {
182- translateAmt = scrollTop / 2
183- scaleAmt = 1
184- } else {
185- translateAmt = 0
186- scaleAmt = scrollTop / headerHeight + 1
187- }
188161
189162 // Parallax total progress
190163 headerMinHeight = toolbar . offsetHeight
@@ -195,8 +168,6 @@ export function useIonHeaderParallax({
195168 let targetHeight = maximumHeight - scrollTop
196169 targetHeight = Math . max ( targetHeight , headerMinHeight )
197170
198- header . style . transform = 'translate3d(0,' + translateAmt + 'px,0) scale(' + scaleAmt + ',' + scaleAmt + ')'
199-
200171 // .toolbar-background: change color
201172 imageOverlay . style . height = `${ targetHeight } px`
202173 imageOverlay . style . opacity = `${ progress } `
0 commit comments