Question

This should be fairly simple. I have one div I am using to show/hide other divs.

On click I want the div that is showing to fade out and the div that is replacing it to pulsate in.

<script>
$(function () {
$(".clicky").click(function () {
    var content_id = $(this).attr('href');
    $('#content').fadeOut(2000).html($(content_id).html()).show("pulsate");;
    return false;
});
});
</script>

Problem is on click this code shows the replacing div first and then also pulsates it in. So it appears before you see the effect. Theres probably a better way to write the code altogether. Any ideas? Thanks.

Was it helpful?

Solution

Try this:

<script>
  $(function () {
    $(".clicky").click(function () {
      var content_id = $(this).attr('href');
      $('#content').fadeOut(2000, function(){
        $(this).html($(content_id).html()).show("pulsate");
      });
      return false;
    });
  });
</script>

The problem you are having is that you aren't waiting for the fadeOut to finish before you start switching out the content and showing the new content.

OTHER TIPS

<script>
   $(function () {
    $(".clicky").click(function () {
      var content_id = $(this).attr('href');
      $('#content').fadeOut(2000,function(){
         $('#content').html($(content_id).html()).show("pulsate");
      });
      return false;
    });
   });
</script>

This will chain so that only once your content has faded out will it pulsate.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top