Hi, I have a weird error where I can't set some st...
# compose-web
a
Hi, I have a weird error where I can't set some style to a Div dynamically, I have this code
Copy code
Div({
	classes(AboutMeStyle.timeline)
		
	window.addEventListener("scroll", {
		val footerOffset = document.querySelector(".${AppStyle.footer}")?.asDynamic()?.offsetTop as Double? ?: return@addEventListener
		val currentOffset by mutableStateOf(window.scrollY + 100)
		
		if (currentOffset < footerOffset) {
			style {
				top(currentOffset.px)
			}
		}
	})
})
If I put a
console.log
inside the condition it gets called so it should be fine, but no style is set, what am I doing wrong ?
d
Try putting the state outside of the
attrs
block and the
style
block outside of the "scroll" listener. Like this:
Copy code
var currentOffset by mutableStateOf(0)
Div({
  style {
    top(currentOffset.px)
  }
  window.addEvenListener("scroll", {
    currentOffset = ...
  }
})
a
Thanks it works, weird that it doesn't work in the event 🤔