1 line
9.7 KiB
JSON
1 line
9.7 KiB
JSON
{"name":"slideToggle","type":"method","title":".slideToggle()","deprecated":null,"removed":null,"desc":"Display or hide the matched elements with a sliding motion.","categories":["effects/sliding","version/1.0","version/1.4.3"],"entries":[{"return":"jQuery","signatures":[{"added":"1.0","argument":[{"desc":"A string or number determining how long the animation will run.","type":[{"name":"Number"},{"name":"String"}],"name":"duration","default":"400","optional":"true"},{"desc":"A function to call once the animation is complete.","name":"complete","type":"Function","optional":"true"}]},{"added":"1.0","argument":{"desc":"A map of additional options to pass to the method.","property":[{"desc":"A string or number determining how long the animation will run.","type":[{"name":"Number"},{"name":"String"}],"name":"duration","default":"400"},{"desc":"A string indicating which easing function to use for the transition.","name":"easing","type":"String","default":"swing"},{"desc":"A Boolean indicating whether to place the animation in the effects queue. If false, the animation will begin immediately. <strong>As of jQuery 1.7</strong>, the queue option can also accept a string, in which case the animation is added to the queue represented by that string. When a custom queue name is used the animation does not automatically start; you must call <code>.dequeue(\"queuename\")</code> to start it.","type":[{"name":"Boolean"},{"name":"String"}],"name":"queue","default":"true"},{"desc":"A map of one or more of the CSS properties defined by the properties argument and their corresponding easing functions.","name":"specialEasing","type":"PlainObject","added":"1.4"},{"desc":"A function to be called for each animated property of each animated element. This function provides an opportunity to modify the Tween object to change the value of the property before it is set.","argument":[{"desc":"The numeric value of the property being animated at each step","name":"now","type":"Number"},{"desc":"An object of properties related to the animation and the element being animated. For information about the tween object and its properties, see <ahref=\"/jQuery.Tween/\">jQuery.Tween</a>","name":"tween","type":"Tween"}],"name":"step","type":"Function"},{"desc":"A function to be called after each step of the animation, only once per animated element regardless of the number of animated properties.","argument":[{"desc":"An enhanced Promise object with additional properties for the animation","name":"animation","type":"Promise"},{"desc":"A number from 0 to 1 indicating the progress of the animation","name":"progress","type":"Number"},{"desc":"A number indicating the remaining number of milliseconds until the scheduled end of the animation","name":"remainingMs","type":"Number"}],"name":"progress","type":"Function","added":"1.8"},{"desc":"A function to call once the animation is complete.","name":"complete","type":"Function"},{"desc":"A function to call when the animation begins.","argument":{"desc":"An enhanced Promise object with additional properties for the animation","name":"animation","type":"Promise"},"name":"start","type":"Function","added":"1.8"},{"desc":"A function to be called when the animation completes (its Promise object is resolved).","argument":[{"desc":"An enhanced Promise object with additional properties for the animation","name":"animation","type":"Promise"},{"desc":"Indicates whether the animation jumped to the end","name":"jumpedToEnd","type":"Boolean"}],"name":"done","type":"Function","added":"1.8"},{"desc":"A function to be called when the animation fails to complete (its Promise object is rejected).","argument":[{"desc":"An enhanced Promise object with additional properties for the animation","name":"animation","type":"Promise"},{"desc":"Indicates whether the animation jumped to the end","name":"jumpedToEnd","type":"Boolean"}],"name":"fail","type":"Function","added":"1.8"},{"desc":"A function to be called when the animation completes or stops without completing (its Promise object is either resolved or rejected).","argument":[{"desc":"An enhanced Promise object with additional properties for the animation","name":"animation","type":"Promise"},{"desc":"Indicates whether the animation jumped to the end","name":"jumpedToEnd","type":"Boolean"}],"name":"always","type":"Function","added":"1.8"}],"name":"options","type":"PlainObject"}},{"added":"1.4.3","argument":[{"desc":"A string or number determining how long the animation will run.","type":[{"name":"Number"},{"name":"String"}],"name":"duration","default":"400","optional":"true"},{"desc":"A string indicating which easing function to use for the transition.","name":"easing","type":"String","default":"swing","optional":"true"},{"desc":"A function to call once the animation is complete.","name":"complete","type":"Function","optional":"true"}]}],"examples":[{"desc":"Animates all paragraphs to slide up or down, completing the animation within 600 milliseconds.","code":"\n$( \"button\" ).click(function() {\n $( \"p\" ).slideToggle( \"slow\" );\n});\n","css":"\n p {\n width: 400px;\n }\n","html":"\n<button>Toggle</button>\n<p>\n This is the paragraph to end all paragraphs. You\n should feel <em>lucky</em> to have seen such a paragraph in\n your life. Congratulations!\n</p>\n"},{"desc":"Animates divs between dividers with a toggle that makes some appear and some disappear.","code":"\n$( \"#aa\" ).click(function() {\n $( \"div:not(.still)\" ).slideToggle( \"slow\", function() {\n var n = parseInt( $( \"span\" ).text(), 10 );\n $( \"span\" ).text( n + 1 );\n });\n});\n","css":"\n div {\n background: #b977d1;\n margin: 3px;\n width: 60px;\n height: 60px;\n float: left;\n }\n div.still {\n background: #345;\n width: 5px;\n }\n div.hider {\n display: none;\n }\n span {\n color: red;\n }\n p {\n clear: left;\n }\n","html":"\n<div></div>\n<div class=\"still\"></div>\n<div style=\"display:none;\">\n</div><div class=\"still\"></div>\n<div></div>\n<div class=\"still\"></div>\n<div class=\"hider\"></div>\n<div class=\"still\"></div>\n<div class=\"hider\"></div>\n<div class=\"still\"></div>\n<div></div>\n<p><button id=\"aa\">Toggle</button> There have been <span>0</span> toggled divs.</p>\n"}],"longdesc":"\n <p>The <code>.slideToggle()</code> method animates the height of the matched elements. This causes lower parts of the page to slide up or down, appearing to reveal or conceal the items. If the element is initially displayed, it will be hidden; if hidden, it will be shown. The <code>display</code> property is saved and restored as needed. If an element has a <code>display</code> value of <code>inline</code>, then is hidden and shown, it will once again be displayed <code>inline</code>. When the height reaches 0 after a hiding animation, the <code>display</code> style property is set to <code>none</code> to ensure that the element no longer affects the layout of the page.</p>\n <p>Durations are given in milliseconds; higher values indicate slower animations, not faster ones. The strings <code>'fast'</code> and <code>'slow'</code> can be supplied to indicate durations of <code>200</code> and <code>600</code> milliseconds, respectively.</p>\n <p>We can animate any element, such as a simple image:</p>\n <pre><code>\n<div id=\"clickme\">\n Click here\n</div>\n<img id=\"book\" src=\"book.png\" alt=\"\" width=\"100\" height=\"123\">\n </code></pre>\n <p>We will cause <code>.slideToggle()</code> to be called when another element is clicked:</p>\n <pre><code>\n$( \"#clickme\" ).click(function() {\n $( \"#book\" ).slideToggle( \"slow\", function() {\n // Animation complete.\n });\n});\n </code></pre>\n <p>With the element initially shown, we can hide it slowly with the first click:</p>\n <p class=\"image four-across\">\n <img src=\"/resources/0042_06_25.png\" alt=\"\"/>\n <img src=\"/resources/0042_06_26.png\" alt=\"\"/>\n <img src=\"/resources/0042_06_27.png\" alt=\"\"/>\n <img src=\"/resources/0042_06_28.png\" alt=\"\"/>\n </p>\n <p>A second click will show the element once again:</p>\n <p class=\"image four-across\">\n <img src=\"/resources/0042_06_29.png\" alt=\"\"/>\n <img src=\"/resources/0042_06_30.png\" alt=\"\"/>\n <img src=\"/resources/0042_06_31.png\" alt=\"\"/>\n <img src=\"/resources/0042_06_32.png\" alt=\"\"/>\n </p>\n <h4 id=\"easing\">Easing</h4>\n <p><strong>As of jQuery 1.4.3</strong>, an optional string naming an easing function may be used. Easing functions specify the speed at which the animation progresses at different points within the animation. The only easing implementations in the jQuery library are the default, called <code>swing</code>, and one that progresses at a constant pace, called <code>linear</code>. More easing functions are available with the use of plug-ins, most notably the <a href=\"http://jqueryui.com\">jQuery UI suite</a>.</p>\n <h4 id=\"callback-function\">Callback Function</h4>\n <p>If supplied, the callback is fired once the animation is complete. This can be useful for stringing different animations together in sequence. The callback is not sent any arguments, but <code>this</code> is set to the DOM element being animated. If multiple elements are animated, it is important to note that the callback is executed once per matched element, not once for the animation as a whole.</p>\n <p><strong>As of jQuery 1.6</strong>, the <code><a href=\"/promise/\">.promise()</a></code> method can be used in conjunction with the <code><a href=\"/deferred.done/\">deferred.done()</a></code> method to execute a single callback for the animation as a whole when <em>all</em> matching elements have completed their animations ( See the <a href=\"/promise/#example-1\">example for .promise()</a> ). </p>\n "}]} |