javascript - css transitions affecting previously modified css properties -
i have script applies css styles element, adds transition style element, , applies css style element. i'm trying have element styles applied instantly, , animate next change. code basic, set styles, set transition styles, set final styles. i'm experiencing first property being changed (the 1 without transition) having transition applied it, though not set transition property until afterwards. have double checked element not have transition property applied it. why this?
also, if leave 50 millisecond delay between applying first styles , transition, works expected.
you have force relayout after first styles applied (so processed without transitions) , can apply styles lead transition. way doing now, opeartions being collapsed 1 operation , undergoing transitions.
the simplest way relayout apply first css properties, settimeout(fn, 1)
apply second set of properties in timer callback. there other ways force relayout requesting properties trigger relayout. don't remember properties off top of head (would take research).
i haven't tried myself, think requesting size property on element such .offsetheight
force relayout. browser realizes there pending style changes , pending style changes might affect size request relayout synchronously before returning .offsetheight
value, solving issue.
a similar question , answer: "force reflow" in css transitions in bootstrap
Comments
Post a Comment