Javascript css transition for vertical size does not work -


i have element named 'frame'. have button code linked 'onlclik'. idea apply height decrease transition 'frame'.

this code results simple frame hide, without transition.

frame.style.csstext+="transition: height 1500ms; -webkit-transition: height 1500ms;"; frame.style.height = "0px"; //frame.style.display = "block";         

(the last line can applied or not, getting same result.)

i can play increasing or decreasing height, in both cases height applied instantly. there not transition...

now surprising behavioor.... transition works fine !!! write height @ styles chrome debugger window , see transition works !!

what reason becasue transition not work @ code level ?

i have similar transition code width increase , works fine.

any idea? thanks

try setting height within settimeout callback:

frame.style.csstext+="transition: height 1500ms; -webkit-transition: height 1500ms;"; settimeout(function() { frame.style.height = "0px"; }, 0); 

settimeout 0 delay instructs browser wait until current ui thread completes before executing supplied callback. more on why settimeout 0 delay useful, check out this thread.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -