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!
$(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
Post a Comment