0

Hi there, I'm dynamically pulling my sidebar image from a database, the image is resized to fit based on which dimension is smaller. Then I'm using a jquery script to reposition the image so that any overflow on the width overflows both sides rather than just on the right using this script:

<script type="text/javascript">


$(document).ready(function()
{
   $("#sidebar-image>img").each(function(i, img) {
        $(img).css({
            position: "relative",
            left: ($(img).parent().width() - $(img).width()) / 2
        });
    });
});
</script>

The problem I'm having is that sometimes the width isn't getting calculated properly, it doesn't seem to get the width of the image everytime and I'm assuming that maybe the jquery is firing before the image is pulled from the database? If I refresh the page the image positions properly.

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by LastMitch
0

Have you tried getting the image dimension using PHP, then passing the information into JQuery?

JQuery shouldn't be firing before the php (Client/Server)

0

@dyingatmidnight

The problem I'm having is that sometimes the width isn't getting calculated properly, it doesn't seem to get the width of the image everytime and I'm assuming that maybe the jquery is firing before the image is pulled from the database? If I refresh the page the image positions properly.

So far the code you provided doesn't show any PHP & MYSQL code. It's only in JQuery? My question is how can anyone help you if you don't put the other code with the JQuery!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.