开发者

jquery animate - dead simple

开发者 https://www.devze.com 2022-12-28 02:44 出处:网络
All I want to do is on .click() is .animate #slip, essentially Im changing the css at the moment from top: 10px to top: 0px

All I want to do is on .click() is .animate #slip, essentially Im changing the css at the moment from top: 10px to top: 0px

Instead of it being quite clunky i'd like to anima开发者_如何学Pythonte the movement on the change of CSS.

Currently use .toggleClass to achieve this:

    $("#div1").click(function() {
        $("#div2t").toggleClass('min');
    });


You can animate like this:

$(selector).click(function() {
  $("#slip").animate({ top: 0; });
});

Unless you need the .animate container, leave it off...the ID selector is, well, as fast as it gets :)

If you wanted the click to animate it back every other click as well, use .toggle() like this:

$(selector).toggle(function() {
  $("#slip").animate({ top: 0; });
}, function() {
  $("#slip").animate({ top: 10; });
});


If I understood you correctly:

#CSS:
.animate #slip {
    top: 10px;
}

#JS
$("element").click(function() {
    $(".animate #slip").animate({ top: 0 });
});


$("#div1").click(function(){
$("#div2t").animate({"top":"0px"},"slow");
);

Where slow is the speed , you can put it fast or time in milliseconds without ""

0

精彩评论

暂无评论...
验证码 换一张
取 消