JeffreyJ
JeffreyJ

Reputation: 127

Animate left not working properly in webkit(Chrome/Safari)

I have an issue with a jquery image slide plugin i'm working on where the images scroll left creating the slideshow. IE and FireFox work fine but Safari/Chrome(WebKit) just wont work.

This the call in question

    $(".nav li").live("click", function () {
    if (lastSelected != null) $(lastSelected).removeClass("selected");
    $(this).addClass("selected");
    place = parseInt($(this).text());
    if (place > last) {
        offset = parseInt(place - last);
        direction = "-=";
    }
    else {
        offset = parseInt(last - place);
        direction = "+=";
    }

// this is where it only works for IE and FF

    $(".slideshow img").each(function () {
        $(this).animate({
            left: direction + (offset * imageWidth) + "px"
        });
    });

// Am I doing something wrong hmm?

    reset = true;
    last = place;
    lastSelected = $(this);
}).css("cursor", "pointer");

Upvotes: 1

Views: 1182

Answers (2)

JeffreyJ
JeffreyJ

Reputation: 127

So I have been doing some debugging an have found that the offset * imageWidth stays 0 in Chrome!

Solution found:

  1. Get the real width and height of an image with JavaScript? (in Safari/Chrome)
  2. http://name1price.com/how-to-get-customers-with-singapore-web-design-basic/jquery-tutorials/149-jquery-get-image-height-or-width-returns-0-problem-.html

These two sources help fix the "jQuery get image height or width returns 0 problem" which was the initial problem. I am now using the fix found in the first solution above and that works fine.

Upvotes: 0

Kanishka Panamaldeniya
Kanishka Panamaldeniya

Reputation: 17576

what is this lastSelected

are you sure

$(lastSelected).removeClass("selected");  

is working ???

because

lastSelected is an `object` not an attribute

try this (assume you have an id attribute)

lastSelected = $(this).attr('id');

and

if (lastSelected != null) $('#'+lastSelected).removeClass("selected");

Upvotes: 1

Related Questions