1

I'm creating a sliding image gallery using jQuery and when given a numeric value the "left" css property works fine, but when given a variable it doesn't do anything. Here's my code:

$(document).mousemove(function(e) {
    var gall = document.getElementById("Gallery");
    var gallOffset = $("div#GalleryHold").offset();
    var offsetX = e.pageX - gallOffset.left;
    var left = gall.style.posLeft;
    var pos = offsetX;
    if (mouseIsOver == true) {
        $('#status').html(offsetX + " " + left + " " + mouseIsOver);
        if (offsetX < 400 && left < 0) {
            $("div#Gallery").stop().animate({
                left: '+=pos'
            }, 600);
        }
        if (offsetX > 600 && left > -1100) {
            $("div#Gallery").stop().animate({
                left: '-=pos'
            }, 600);
        }
    }
    else if (mouseIsOver == false) {
        $('#status').html(offsetX + " " + left + " " + mouseIsOver);
    }
});​
2
  • are you saying animate({left: '+=pos'} doesnt work? Commented Jul 13, 2012 at 21:06
  • Try {left: '+=' + pos} Commented Jul 13, 2012 at 21:07

1 Answer 1

7

'+=pos' is a constant string.

You probably want '+=' + pos, which will evaluate to a string like '+=50'

Sign up to request clarification or add additional context in comments.

2 Comments

Same with the '-=pos' line a few lines down, should also be changed to '-=' + pos
@TaylorBishop - If you click the green tick by this answer it will mark it as accepted. This will a) tell other people who find this question that you thought it was the right answer, b) give you a small reputation boost as a reward for giving useful feedback and c) contribute to your "% answered" statistic which hints to other users how responsive you are to the answers they give you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.