0

I am having a JQuery problem today here's the code dump to start us off

$(function() {
    var distance = 0;
    $('.right').click(function() {
        distance -= 100;
        $('#container').css('transform', 'translateX(' + distance + '%)')
        console.log(distance);
    });
    $('.left').click(function() {
        distance += 100;
        $('#container').css('transform', 'translateX(' + distance + '%);')
        console.log(distance);
    });
});

What this code is doing is move width of the users page 100% to the left or 100% to the right. When I click a button with a class name of 'right' it works all fine, but when I click a class name of 'left' it displays it in the console as it should but it doesn't move the page, it needs me to press another button before it updates.

0

1 Answer 1

3

Just remove ; from this line:

$('#container').css('transform', 'translateX(' + distance + '%);')
//                                                             ^ Remove it

$('.left').click(function() {
    distance += 100;
    $('#container').css('transform', 'translateX(' + distance + '%)')
    console.log(distance);
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, I think all I needed was another set of eyes on it :)

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.