1110
1110

Reputation: 6839

Moving left right with jQuery

I am jQuery beginner :) I am trying to move from left to right but all I did is moving to the right. How to move it back?

$(function () {
        $('#box').click(function () {
            $(this).animate({
                "left" : "300px"
        }, 4000);
    });
});

Also I have update panel on my page with left right button that do some things in code behind. How to call this left/right function from code behind?

Upvotes: 1

Views: 4290

Answers (1)

Niclas Sahlin
Niclas Sahlin

Reputation: 1137

To move it back to the left you just append another animate:

$(function () {
  $('#box').click(function () {
    $(this).animate({
      "left" : "300px"
    }, 4000).animate({
      "left" : "0px"
    }, 4000);
  });
});

This is an anonymous function as event handler you can't call, it will only run on the click events on the div. You could move it outside

$(function () {
  $('#box').click(boxAnimation);
});

function boxAnimation() {
  $(this).animate({
    "left" : "300px"
  }, 4000).animate({
    "left" : "0px"
  }, 4000);
}

and then maybe this will help.

EDIT:

I found an article describing how you can call javascript from the code-behind.

Hope it helps

Upvotes: 2

Related Questions