Commit 68f81a0 1 parent 089b3a0 commit 68f81a0 Copy full SHA for 68f81a0
File tree 1 file changed +9
-5
lines changed
1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -8,14 +8,16 @@ pub fn use_lock_html_scroll(is_lock: MaybeSignal<bool>) {
8
8
let remove_style_el = move || {
9
9
style_el. update_value ( move |el| {
10
10
if let Some ( el) = el. take ( ) {
11
- let head = document ( ) . head ( ) . expect ( "head no exist" ) ;
12
- _ = head. remove_child ( & el) ;
11
+ el. remove ( ) ;
13
12
}
14
13
} ) ;
15
14
} ;
16
15
17
- create_render_effect ( move |_| {
18
- if is_lock. get ( ) {
16
+ create_render_effect ( move |prev| {
17
+ let is_lock = is_lock. get ( ) ;
18
+ let prev: bool = prev. unwrap_or_default ( ) ;
19
+
20
+ if is_lock && !prev {
19
21
let head = document ( ) . head ( ) . expect ( "head no exist" ) ;
20
22
let style = document ( )
21
23
. create_element ( "style" )
@@ -24,9 +26,11 @@ pub fn use_lock_html_scroll(is_lock: MaybeSignal<bool>) {
24
26
style. set_text_content ( Some ( "html { overflow: hidden; }" ) ) ;
25
27
_ = head. append_child ( & style) ;
26
28
style_el. set_value ( Some ( style) ) ;
27
- } else {
29
+ } else if !is_lock && prev {
28
30
remove_style_el ( ) ;
29
31
}
32
+
33
+ is_lock
30
34
} ) ;
31
35
32
36
on_cleanup ( remove_style_el)
You can’t perform that action at this time.
0 commit comments