Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Set a margin work, set a margin doesn’t work?!

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #36362
    Vermaas
    Participant

    Hi all,

    I was playing around with some jQuery and on this moment i’ve got a very strange issue. I want to set a margin to an image, while loading the page. This is to get the image in de middle and the jQuery code i’ve used is very simple:


    /*
    set the height of the ref-items
    */
    $('.ref-item').each(function() {
    var imgHeight = $(this).find('img').height();
    var topMargin = (84 - imgHeight) / 2;

    var imgWidth = $(this).find('img').width();
    var leftMargin = (159 - imgWidth) / 2;

    $('.ref-item img').css('marginTop', topMargin).css('marginLeft', leftMargin);
    $('.ref-item canvas').css('marginTop', topMargin).css('marginLeft', leftMargin);
    });

    But sometimes the margin’s are correct and sometimes they are not.. I can’t figure out why.. The page can be found here: http://klanten.yellowduckwebdesign.nl/multiprotect/. It’s at the bottom of the page, the picture’s which are desatured.

Viewing 1 post (of 1 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.