jquery - SlideDown once* then Animate depending on clicks. -


my code both animations simultaneously.

  • slidesdown
  • animate div

i slidedown animation occur first, , when complete, animation.

note: first slidedown animation occurs once, while remaining animations reoccurring. i.e: clicking on other tags.

p.s: have tried doing callback stops remaining code working due me wanting do first slidedown animation once.

please see jsfiddle demo proper demo.

thanks in advance!

please have @ code below. have left comments reference.

$(function() {     var content = $('#content'),         contentheight = content.height(),         nav = $('#nav'),         count = 0;      // on load content height shorter     content.height(100);      nav.find('a').on('click', function() {          var $this = $(this),             parent =  $this.parent(),             targetelement = $this.attr('href');          //does slide down animation once                 if (count === 0) {             content.animate({'height': contentheight });             count = 1;         }          //only add active class if parent not have , animate         if ( !parent.hasclass('active') ) {              parent.addclass('active');              //animate in             $(targetelement).animate({                 left: '-=200px',                 'margin-left': '50%',                 opacity: 1             }, 500);              //gets older clicked element             var oldclickedelement = $('.active').not(parent).removeclass('active').find('a').attr('href');              //only if old click element exists animation             if (oldclickedelement) {                 //animate out + reset start                 $(oldclickedelement).animate({                     left: 0,                     'margin-left': '-50%',                      opacity: 0                 }, 500, function() {                      $(oldclickedelement).css({                         'margin-left' : '100%',                         left: 0                     });                 });                         }         }           return false;     });  }); 

use callback function call other animation after slidedown

content.animate({'height': contentheight },function() {    //do other animation here, function called after slidedown finished. }); 

jquery .animate api reference

edit:

  if (count === 0) {         content.animate({'height': contentheight },function(){            //do animation code here         });         count = 1;     } else {      //only add active class if parent not have , animate     if ( !parent.hasclass('active') ) {          parent.addclass('active');          //animate in         $(targetelement).animate({             left: '-=200px',             'margin-left': '50%',             opacity: 1         }, 500);          //gets older clicked element         var oldclickedelement = $('.active').not(parent).removeclass('active').find('a').attr('href');          //only if old click element exists animation         if (oldclickedelement) {             //animate out + reset start             $(oldclickedelement).animate({                 left: 0,                 'margin-left': '-50%',                  opacity: 0             }, 500, function() {                  $(oldclickedelement).css({                     'margin-left' : '100%',                     left: 0                 });             });                     }     }   } 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -