get height of jQuery popup when it shows up -
i want geht height of popup when loaded can set left/top value , make sure not out of viewport. @ first time popup toggled, there's hight of static div available, not including content ajax.
$(".td_id").click(function(e) { var leftval = e.pagex+10; var topval = e.pagey; var bodytop = document.documentelement.scrolltop; topval -= bodytop; win = $(window).height(); wincenter = win / 2; $.post("ajax.php",{do:'load_data'},function(table){ $(".popup tbody").html(table); } ); $(".popup").toggle(); popup = $(".popup").height(); if (topval > wincenter) topval -= popup; if ((topval+popup) > (win + 10)) topval = win-10-popup; if (topval < 10) topval = 10; $(".popup").css({left:leftval,top:topval}); });
how height after content received , added popup div?
the popup seems getting content ajax post, , trying calculate height outside post callback (before popup gets content ajax post), hence height not calculated proper. try replacing height calculation code inside ajax post success callback function, as:
... $.post("ajax.php",{do:'load_data'},function(table){ $(".popup tbody").html(table); $(".popup").toggle(); popup = $(".popup").height(); if (topval > wincenter) topval -= popup; if ((topval+popup) > (win + 10)) topval = win-10-popup; if (topval < 10) topval = 10; $(".popup").css({left:leftval,top:topval}); }); ...
Comments
Post a Comment