1

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
1110
  • 7,829
  • 55
  • 176
  • 334

1 Answers1

2

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

Community
  • 1
  • 1
Niclas Sahlin
  • 1,125
  • 9
  • 15
  • Thanks. And what about call this move functions from code behind. – 1110 May 14 '11 at 10:11
  • @1110 check the link and see if you can find the answer there. I'm no WebForms developer so I think other people can answer that part better than i can :) – Niclas Sahlin May 14 '11 at 10:21
  • the `$('#box').click(boxAnimation);` is the answer to your second question. All you need is a named function. – jackJoe May 14 '11 at 11:15