jquery - How to hide a toggled div and show another in its place -


i'm attempting put menu theme i'm working on i'm having trouble getting part of work. specifically, want able click on link , have div slide down , fade in, click link , have div fade , slide out new div slide , fade in place. @ moment have working when hiding div using same link show it, different links pile divs on top of each other.

here's code i'm using:

jquery.fn.fadethenslidetoggle = function () {     if (this.is(":hidden")) {         return this.slidedown(500, "linear").fadeto(500, 1, "linear");     } else {         return this.fadeto(500, 0, "linear").slideup(500, "linear");     } }; $(document).ready(function () {     $('#toggleabout').click(function () {         $('#about').fadethenslidetoggle();         return false;     });     $('#toggleprojects').click(function () {         $('#projects').fadethenslidetoggle();         return false;     });     $('#toggleconnect').click(function () {         $('#connect').fadethenslidetoggle();         return false;     });     $('#toggleexchange').click(function () {         $('#exchange').fadethenslidetoggle();         return false;     });     $('#toggleextras').click(function () {         $('#extras').fadethenslidetoggle();         return false;     });     $('#togglesearch').click(function () {         $('#search').fadethenslidetoggle();         return false;     }); }); 

with previous menu designed used this:

$('#toggleconnect').click(function () {     $(".menubox:not(#connect)").slideup(500, "linear");     $('#connect').delay(600).slidetoggle(500, "linear");     return false; }); 

this works fine when calling on single effect complexity of want here seems break this. i've tried few things nothing seems work me. appreciated.

codepen

try

jquery.fn.fadethenslidetoggle = function(opts) {     opts = opts || {};      var hide = function(el, complete){         var p1, p2;         el.finish();         p1= el.fadeto(500, 0, "linear").promise();         p2 = el.slideup(500, "linear").promise();         $.when(p1, p2).done(complete)     }     var show  = function(el, complete){         var p1, p2;             el.finish();         p1 = el.slidedown(500, "linear").promise();         p2 = el.fadeto(500, 1, "linear").promise();         $.when(p1, p2).done(opts.complete)     }      if (this.is(":hidden")) {         if(opts.divs){             hide(opts.divs.filter(':visible').not(this), $.proxy(function(){                 show(this, opts.complete)             }, this))         } else {             show(this, opts.complete)         }     } else {         hide(this, opts.complete)     }       return this; }; $(document).ready(function() {     var divs = $('#about, #projects, #connect, #exchange, #extras, #search').hide()     $('#toggleabout').click(function() {         $('#about').fadethenslidetoggle({             divs: divs         });         return false;     });     $('#toggleprojects').click(function() {         $('#projects').fadethenslidetoggle({             divs: divs         });         return false;     });     $('#toggleconnect').click(function() {         $('#connect').fadethenslidetoggle({             divs: divs         });         return false;     });     $('#toggleexchange').click(function() {         $('#exchange').fadethenslidetoggle({             divs: divs         });         return false;     });     $('#toggleextras').click(function() {         $('#extras').fadethenslidetoggle({             divs: divs         });         return false;     });     $('#togglesearch').click(function() {         $('#search').fadethenslidetoggle({             divs: divs         });         return false;     }); }); 

demo: fiddle


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -