mirror of
https://github.com/adoyle0/thaw.git
synced 2025-01-22 22:09:22 -05:00
fix: use_lock_html_scroll (#215)
This commit is contained in:
parent
089b3a024d
commit
68f81a04eb
1 changed files with 9 additions and 5 deletions
|
@ -8,14 +8,16 @@ pub fn use_lock_html_scroll(is_lock: MaybeSignal<bool>) {
|
|||
let remove_style_el = move || {
|
||||
style_el.update_value(move |el| {
|
||||
if let Some(el) = el.take() {
|
||||
let head = document().head().expect("head no exist");
|
||||
_ = head.remove_child(&el);
|
||||
el.remove();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
create_render_effect(move |_| {
|
||||
if is_lock.get() {
|
||||
create_render_effect(move |prev| {
|
||||
let is_lock = is_lock.get();
|
||||
let prev: bool = prev.unwrap_or_default();
|
||||
|
||||
if is_lock && !prev {
|
||||
let head = document().head().expect("head no exist");
|
||||
let style = document()
|
||||
.create_element("style")
|
||||
|
@ -24,9 +26,11 @@ pub fn use_lock_html_scroll(is_lock: MaybeSignal<bool>) {
|
|||
style.set_text_content(Some("html { overflow: hidden; }"));
|
||||
_ = head.append_child(&style);
|
||||
style_el.set_value(Some(style));
|
||||
} else {
|
||||
} else if !is_lock && prev {
|
||||
remove_style_el();
|
||||
}
|
||||
|
||||
is_lock
|
||||
});
|
||||
|
||||
on_cleanup(remove_style_el)
|
||||
|
|
Loading…
Add table
Reference in a new issue