I am trying to add animation to a particular Div h...
# compose-web
r
I am trying to add animation to a particular Div here by using StyleSheet Keyframes
Copy code
object ModalStyle: StyleSheet() {
    val btsModal by style {
        keyframes {
            from { this.property("top",0.px) }
            to { this.property("top", 30.px) }
        }
    }
}
I added this to my div's style like below, but its not animating
Copy code
Div(
        attrs = {
            classes("modal")
            id(id)
            tabIndex(-1)
            attr("aria-labelledby", label)
            style {
                display(displayState.value)
//                background("#0000004d")
                position(Position.Relative)
                animation(ModalStyle.btsModal) {
                    duration(10.s)
                }
            }
        }
    )
But no animation happens
o
Copy code
object ModalStyle: StyleSheet() {
    val animTransition by keyframes {
        from { this.property("top",0.px) }
        to { this.property("top", 30.px) }
    }
    val btsModal by style {

    }
}
then in Div
Copy code
Div(
        attrs = {
            classes("modal")
            id(id)
            tabIndex(-1)
            attr("aria-labelledby", label)
            style {
                display(displayState.value)
//                background("#0000004d")
                position(Position.Relative)
                animation(ModalStyle.animTransition) {
                    duration(10.s)
                }
            }
        }
    )
also somewhere at the root you might need to call a composable:
Copy code
// somewhere like:
renderComposable("root") {
   Style(ModalStyle)
}
r
hey, this works actually
I knew I needed to use KeyFrames, but not sure, how in compose web Are all the CSS things need to be applied by
by delegate
hello @hfhbd I was going through your bootstrap-compose somehow I a, having problem with this particular line
hrmlDivElement.addEventListener()
is not available in my project But when I saw in your project, IDE is able to resolve it
Not sure why is this happening
h
addEventListener
is a generated function of
EventTarget
, defined in the Kotlin JS web api:
org.w3c.dom.events
. Sounds like a missing import
r
I needed to do
unsafeCast
to
EventTarget
after that only it worked for me I checked your project , but there was no such case
😕
b
I suspect you have the wrong HTMLDivElement import. Try removing the type from lambda and let the compiler infer it instead
h
Or what is the type of the variable?
r
I checked the heirarchy , it was the same @Big Chungus
Or what is the type of the variable?
HTMLDivElement
h
Strange, it works in different projects without problems for me.
Copy code
val s: HTMLDivElement
s.addEventListener("asf", callback =  { f ->

})
r
Wierd :
😕
I checked the heirarchy in Web, EventTarget is implemented by Element which is extended by HTMLDivElement, so for me
unsafeCast
worked 😐