{"id":510,"date":"2013-06-11T22:27:16","date_gmt":"2013-06-11T22:27:16","guid":{"rendered":"http:\/\/tregner.com\/flare-blog\/?p=510"},"modified":"2013-06-11T22:27:16","modified_gmt":"2013-06-11T22:27:16","slug":"embellishing-the-jquery-slides-with-fade-effects","status":"publish","type":"post","link":"https:\/\/tregner.com\/flare-blog\/embellishing-the-jquery-slides-with-fade-effects\/","title":{"rendered":"Embellishing the jQuery Slides with Fade Effects"},"content":{"rendered":"<p dir=\"ltr\">If you saw <a href=\"https:\/\/tregner.com\/flare-blog\/show-and-hide-with-jquery-in-html5-output\/\" target=\"_blank\">yesterday\u2019s post<\/a>, you may have asked, why include the function that does nothing in the parameters for the calls to slideUp() and slideDown()? For yesterday\u2019s example, there is no good reason. The functions will work with no parameters. The first parameter passed is duration. Slow is a nice speed. According to <a href=\"http:\/\/api.jquery.com\/slideUp\/\" target=\"_blank\">slideUp()<\/a> and <a href=\"http:\/\/api.jquery.com\/slideDown\/\" target=\"_blank\">slideDown()<\/a> documentation, the duration is 600 milliseconds.<\/p>\n<p dir=\"ltr\">The second parameter is a deferred <a href=\"http:\/\/en.wikipedia.org\/wiki\/Callback_(computer_programming)\" target=\"_blank\">callback<\/a> function. When included in the parameters, this \u2018complete\u2019 function is called at the end. For example other <a href=\"http:\/\/api.jquery.com\/category\/effects\/\">jQuery effects<\/a> can be used to embellish the animation when the slide animation is completed.<\/p>\n<p dir=\"ltr\">By the way, <a href=\"http:\/\/api.jquery.com\/slideToggle\/\">slideToggle()<\/a> would accomplish yesterday\u2019s example more efficiently. But if we want to differentiate the slideUp() and slideDown() animations, the if..else comes in handy.<\/p>\n<p>Here is yesterday\u2019s example embellished with different animations after the completion of slideUp() and slideDown(). After slideUp(), the body of the topic will fade out with <a href=\"http:\/\/api.jquery.com\/fadeOut\/\">fadeOut()<\/a> and back in with <a href=\"http:\/\/api.jquery.com\/fadeIn\/\">fadeIn()<\/a>. After slideDown(), the sliding text will fade out and back in:<\/p>\n<pre class=\"lang:js decode:true\">function slideContent(id) {\n    if ($('#' + id).css('display') == 'none') {\n        $('#' + id).slideDown('slow', function () {\n            $(this).fadeOut();\n            $(this).fadeIn();\n        });\n    }\n    else {\n        $('#' + id).slideUp('slow', function () {\n            $('body').fadeOut();\n            $('body').fadeIn();\n        });\n    }\n}<\/pre>\n<p>Here is the behavior:<\/p>\n<p><a href=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/06\/fade-in-fade-out.mp4\">fade-in-fade-out<\/a><\/p>\n<p>And the new version of the topic:<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;html xmlns:MadCap=\"http:\/\/www.madcapsoftware.com\/Schemas\/MadCap.xsd\" MadCap:lastBlockDepth=\"2\" MadCap:lastHeight=\"155\" MadCap:lastWidth=\"811\"&gt;\n    &lt;head&gt;\n        &lt;link href=\"Resources\/Stylesheets\/Styles.css\" rel=\"stylesheet\" type=\"text\/css\" \/&gt;\n    &lt;\/head&gt;\n    &lt;body&gt;\n        &lt;h1&gt;Topic Title&lt;\/h1&gt;\n        &lt;p&gt;\n            &lt;script type=\"text\/javascript\"&gt;\/*&lt;![CDATA[*\/function slideContent(id) {\n    if ($('#' + id).css('display') == 'none') {\n        $('#' + id).slideDown('slow', function () {\n            $(this).fadeOut();\n            $(this).fadeIn();\n        });\n    }\n    else {\n        $('#' + id).slideUp('slow', function () {\n            $('body').fadeOut();\n            $('body').fadeIn();\n        });\n    }\n}\/*]]&gt;*\/&lt;\/script&gt;\n        &lt;\/p&gt;\n        &lt;p onclick=\"slideContent('show-hide')\"&gt;Expand\/Collapse&lt;\/p&gt;\n        &lt;p id=\"show-hide\" class=\"space\"&gt;Delete this text and replace it with your own content.&lt;\/p&gt;\n    &lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you saw yesterday\u2019s post, you may have asked, why include the function that does nothing in the parameters for the calls to slideUp() and slideDown()? For yesterday\u2019s example, there is no good reason. The functions will work with no parameters. The first parameter passed is duration. Slow is a nice speed. According to slideUp()&hellip; <a class=\"more-link\" href=\"https:\/\/tregner.com\/flare-blog\/embellishing-the-jquery-slides-with-fade-effects\/\">Continue reading <span class=\"screen-reader-text\">Embellishing the jQuery Slides with Fade Effects<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[],"_links":{"self":[{"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/posts\/510"}],"collection":[{"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/comments?post=510"}],"version-history":[{"count":5,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/posts\/510\/revisions"}],"predecessor-version":[{"id":516,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/posts\/510\/revisions\/516"}],"wp:attachment":[{"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/media?parent=510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/categories?post=510"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/tags?post=510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}