mirror of
https://github.com/adoyle0/thaw.git
synced 2025-02-02 08:34:15 -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 || {
|
let remove_style_el = move || {
|
||||||
style_el.update_value(move |el| {
|
style_el.update_value(move |el| {
|
||||||
if let Some(el) = el.take() {
|
if let Some(el) = el.take() {
|
||||||
let head = document().head().expect("head no exist");
|
el.remove();
|
||||||
_ = head.remove_child(&el);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
create_render_effect(move |_| {
|
create_render_effect(move |prev| {
|
||||||
if is_lock.get() {
|
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 head = document().head().expect("head no exist");
|
||||||
let style = document()
|
let style = document()
|
||||||
.create_element("style")
|
.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; }"));
|
style.set_text_content(Some("html { overflow: hidden; }"));
|
||||||
_ = head.append_child(&style);
|
_ = head.append_child(&style);
|
||||||
style_el.set_value(Some(style));
|
style_el.set_value(Some(style));
|
||||||
} else {
|
} else if !is_lock && prev {
|
||||||
remove_style_el();
|
remove_style_el();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is_lock
|
||||||
});
|
});
|
||||||
|
|
||||||
on_cleanup(remove_style_el)
|
on_cleanup(remove_style_el)
|
||||||
|
|
Loading…
Add table
Reference in a new issue