javascript - on('click') function fires on second click -


i have problem, got li toggles whenever element clicked, problem i'm trying navigate window center li when "click" element click. it's working problem is, script works on second click?

my theory since li in display:none, it's not reading on first click, rather on second click. there anyway solve in way fire toggle plus window navigation @ same time?

and there way move dynamically(animate) in smooth way?

thanks guys!

sample jsfiddle

 $(document).on('click', "#click", function(){    var viewportheight = $(window).height(),       foo = $('ul li:nth-child(2)'),       elheight = foo.height(),       eloffset = foo.offset();   $(window).scrolltop(eloffset.top + (elheight/2) - (viewportheight/2));   $(foo).slidetoggle();   }); 

first mate try set visibility: hidden; not display none

if not work too, try set timer work when click directly, time call calculate function again ... , work .. can test more easy .. add under function ..

        $(document).on("mousemove", "#click", function(){    var viewportheight = $(window).height(),       foo = $("ul li:nth-child(2)"),       elheight = foo.height(),       eloffset = foo.offset();   $(window).scrolltop(eloffset.top + (elheight/2) - (viewportheight/2));   $(foo).slidetoggle();   }); 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -