Combine Slide and Fade Functions

$.fn.slideFadeToggle  = function(speed, easing, callback) {
        return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);
}; 

Usage

$("#something").click(function() {
   $(this).slideFadeToggle();
});

Comments

  1. User Avatar
    Dor
    Permalink to comment#

    As if you read my thoughts. Thanks Chris :D

  2. User Avatar
    Tofudisan
    Permalink to comment#

    This is beautiful! I can imagine using this effect on many things.

    Thanks!

  3. User Avatar
    Nightmaster

    Any demo? I would like to see it if there is some.

  4. User Avatar
    Steviss
    Permalink to comment#

    Thanks, m8! Your site is great! Found a lot of usefull tips!

  5. User Avatar
    El garch Hicham
    Permalink to comment#

    Hello, is there any Demo to download, it doesn’t work for me.
    thx for the nice post.

  6. User Avatar
    Amir Monfared
    Permalink to comment#

    it’s nice , but I think it would be better if there was a demo page just like “Downloads”

  7. User Avatar
    Rob Salaman

    This is an awesome post Chris cheers.

  8. User Avatar
    miyijura
    Permalink to comment#

    Excellent effect and very easy to modify!
    Thanks!

  9. User Avatar
    zing
    Permalink to comment#

    Always nice to see a demo or example.

  10. User Avatar
    JeyKeu
    Permalink to comment#

    Thanks @Chris.

    @Amir Monfared: there you go, http://jsfiddle.net/jeykeu/ejcn8/

  11. User Avatar
    jake
    Permalink to comment#

    Thanks once again Chris. Over & over again I find what I’m looking for through your site.

  12. User Avatar
    Kalrav Bhatnagar
    Permalink to comment#

    Thanks a lot Chris! Nice work

  13. User Avatar
    Frederik
    Permalink to comment#

    Nice one, just in case someone else wants to use this:

    You might want to add padding: 'toggle' in order to prevent a jumpy animation when you’re using paddings on the element you want to toggle.

  14. User Avatar
    Nithin

    Check out the working demo here

    Thanks,
    Nithin

  15. User Avatar
    Andy Fleming
    Permalink to comment#

    Here are the corresponding functions for explicitly “slide-fading” in or out.

    $.fn.slideFadeToggle  = function(speed, easing, callback) {
        return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);
    };
    
    $.fn.slideFadeIn  = function(speed, easing, callback) {
        return this.animate({opacity: 'show', height: 'show'}, speed, easing, callback);
    };
    
    $.fn.slideFadeOut  = function(speed, easing, callback) {
        return this.animate({opacity: 'hide', height: 'hide'}, speed, easing, callback);
    };
    
    
  16. User Avatar
    Corry Frydlewicz
    Permalink to comment#

    Hey Guys,
    If I want this to toggle between display: none and display: flex with all the proper compatibility, is that possible? Or should I just create a new element within to display: flex ?

    • User Avatar
      Paul Revival
      Permalink to comment#

      It’ll be better to wrap your ‘flex’-element to another one with display:block and use this function on it.

  17. User Avatar
    Vinny
    Permalink to comment#

    This is better achieved in css;

    CSS:

    .slide {
    position: relative;
    left: 50%;
    height: 20px;
    animation: 5s slide;
    }

    @keyframes slide {
    from: { left: 100%; opacity: 0; }
    to: { left: 50%; opacity: 1; }
    }

  18. User Avatar
    gokul
    Permalink to comment#

    submenu……….

    $(document).ready(function () {
                    $('.parent').on("click", function () {
                        $(this).find('li:first a').addClass('');
                        $(this).find('li:first').addClass('');
                        $('li a').removeClass('sel1');
                        $('li').removeClass('seler');
                        $(this).find(".sub-nav1").fadeToggle("slow");
                        $(this).siblings().find(".sub-nav1").hide();
    
                   if ($(".sub-nav1:visible").length === 0) {
                        $("#menu-overlay").hide();
                        $(this).find('li:first a').removeClass('sel1');
                        $(this).find('li:first').removeClass('seler');
                    } else {
                        $("#menu-overlay").show();
                        $('ul.sub-nav1 li a').addClass('mar');
                        $('ul.sub-nav1 li a').addClass('selcol');
                        $(this).find('li:first a').addClass('sel1');
                        $(this).find('li:first').addClass('seler');
                        // $(this).find('ul').slideToggle();
                    }
                });
    

Submit a Comment

Posting Code

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.

icon-closeicon-emailicon-linkicon-logo-staricon-menuicon-searchicon-staricon-tag