0

I know there are other and more preferred methods, but I'm trying to give a div img a bounce effect using jQuery.

I'm trying to loop

 $('#downarrow').animate({bottom:'4px'});
  $('#downarrow').animate({bottom:'0px'});

Any help would be awesome. Thanks!

1
  • Wouldnt this be easier in css keyframes animation? Commented Jun 21, 2016 at 3:02

2 Answers 2

2

One very simple solution:

function bounceUp(){
    $('#downarrow').animate({bottom:'4px'}, 1000, bounceDown);
}
function bounceDown(){
    $('#downarrow').animate({bottom:'0px'}, 1000, bounceUp);
}

bounceUp();

An example: https://jsfiddle.net/DerekL/nd8kf61s/

Sign up to request clarification or add additional context in comments.

1 Comment

Just what I needed. I'll accept this in 8 minutes! Thank you!
1

You can use jQuery to addClass or toggleClass. But this approach using the css animation.

$(document).ready(function() {
  $('.arrow').toggleClass('upp');
});
.arrow {
  position: relative;
  bottom: 0px;
}
.upp {
  -webkit-animation: mymove 1.5s infinite;
  /* Chrome, Safari, Opera */
  animation: mymove 1.5s infinite;
}
/* Chrome, Safari, Opera */

@-webkit-keyframes mymove {
  0% {
    bottom: 10px;
  }
  50% {
    bottom: 0px;
  }
  100% {
    bottom: 10px
  }
}
@keyframes mymove {
  0% {
    bottom: 10px;
  }
  50% {
    bottom: 0px;
  }
  100% {
    bottom: 10px
  }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="arrow">
  hey
</div>

Comments

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.