javascript - How do i get the width and height after using appendTo -
basically, have parent div named 'wrapper'
, adding other div's: divimg
, counter , caption. centering 'wrapper'
.
appending divs 'wrapper' works ok. i'm stuck on how center 'wrapper'
. reason, cannot width , height of 'wrapper' after using appendto
. it's same , height.
how width , height after using appendto
, see code below:
function appendimage() { var wrapperwidth; var wrapperheight; var windowwidth = $(window).width(); var windowheight = $(window).height(); var wrapper = $("#modal-wrapper"); var divimg = $("<div></div>") .hide() .attr("id", "container-img") .appendto(wrapper); var counter = $("<p></p>") .hide() .addclass("slideshowcounter") .text(text goes here...) .appendto(wrapper); var caption = $("<p></p>") .hide() .addclass("imgcaption") .text(caption goes here...) .appendto(wrapper); // preload image var img = new image(); img.src = src; img.onload = function() { // set image width / height $(this).width(this.width).height(this.height).appendto(divimg); wrapperwidth = wrapper.outerwidth(); // error, same width alert(wrapperwidth); wrapperheight = wrapper.outerheight(); wrapper.css({ width: wrapperwidth, height: wrapperheight, left: ((windowwidth - wrapperwidth) / 2 + $(window).scrollleft()), top: ((windowheight - wrapperwidth) / 2 + $(window).scrolltop()) }).show( "slow", function() { // fadein image , other divimg.fadein(800); }); } }
Comments
Post a Comment