반응형
Notice
Recent Posts
Recent Comments
Link
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
Tags
more
Archives
Today
Total
관리 메뉴

스터디 용 블로그

animate and image up and down 본문

카테고리 없음

animate and image up and down

워후 2015. 3. 10. 17:33
반응형

I'm trying to animate and image up and then down with jquery.

It should behave like this:

When the page loads it shows 50% of the image. If someone clicks on the image it then animates the div up the page. If the user click again it moves back down the page.

html

 <div id="slidebottom" class="slide">
     <div class="inner"><img src="images/sze.jpg" alt="" class="try" /></div>
 </div>

jquery

$(document).ready(function() {
    $('.try').click(function() {
        $(".inner").animate({
            top: '-=100px'
        }, 2000);
    });
});

I need help, how to reverse the animation after click two. (At the moment every time I click, the container moves up)

Thank you masters

shareimprove this question

You can try using the .toggle() method, which takes two functions and alternates between executing each one of them on click:

$(document).ready(function(){
  $('.try').toggle(function() {
    $(".inner").animate({top: '-=100px'}, 2000);
  }, function() {
    $(".inner").animate({top: '+=100px'}, 2000);
  });
});

However, I personally would use a class and CSS3 Transitions.

shareimprove this answer
   
It is possible to not work in Chrome the animate? FF work this, but in Chrome after click the image first the image jump down, and animate up, if i click again than animate the hole site..crazy effect –  holian Jul 18 '12 at 8:57
   
i tried in Chrome , IE9, Safari...only FF handle it as ascpected. –  holian Jul 18 '12 at 9:01
   
i think i do it with css –  holian Jul 18 '12 at 9:02













































http://stackoverflow.com/questions/18349108/animating-a-div-up-and-down-repeatedly




$(".show_up").click(function() {

$(this).siblings("ul").animate({

top: "-=100%"}, 500);

});


$(".show_down").click(function() {

$(this).siblings("ul").animate({

top: "+=100%"}, 500);

});








반응형
Comments