control-freak-ide/Control-Freak-Documentation/jQuery/docs/entries/fadeTo.json
plastic-hub-dev-node-saturn 538369cff7 latest
2021-05-12 18:35:18 +02:00

1 line
5.3 KiB
JSON

{"name":"fadeTo","type":"method","title":".fadeTo()","deprecated":null,"removed":null,"desc":"Adjust the opacity of the matched elements.","categories":["effects/fading","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":"String"},{"name":"Number"}],"name":"duration"},{"desc":"A number between 0 and 1 denoting the target opacity.","name":"opacity","type":"Number"},{"desc":"A function to call once the animation is complete.","name":"complete","type":"Function","optional":"true"}]},{"added":"1.4.3","argument":[{"desc":"A string or number determining how long the animation will run.","type":[{"name":"String"},{"name":"Number"}],"name":"duration"},{"desc":"A number between 0 and 1 denoting the target opacity.","name":"opacity","type":"Number"},{"desc":"A string indicating which easing function to use for the transition.","name":"easing","type":"String","optional":"true"},{"desc":"A function to call once the animation is complete.","name":"complete","type":"Function","optional":"true"}]}],"examples":[{"desc":"Animates first paragraph to fade to an opacity of 0.33 (33%, about one third visible), completing the animation within 600 milliseconds.","code":"\n$( \"p:first\" ).click(function() {\n $( this ).fadeTo( \"slow\", 0.33 );\n});\n","html":"\n<p>\nClick this paragraph to see it fade.\n</p>\n\n<p>\nCompare to this one that won't fade.\n</p>\n"},{"desc":"Fade div to a random opacity on each click, completing the animation within 200 milliseconds.","code":"\n$( \"div\" ).click(function() {\n $( this ).fadeTo( \"fast\", Math.random() );\n});\n","css":"\n p {\n width: 80px;\n margin: 0;\n padding: 5px;\n }\n div {\n width: 40px;\n height: 40px;\n position: absolute;\n }\n #one {\n top: 0;\n left: 0;\n background: #f00;\n }\n #two {\n top: 20px;\n left: 20px;\n background: #0f0;\n }\n #three {\n top: 40px;\n left:40px;\n background:#00f;\n }\n","html":"\n<p>And this is the library that John built...</p>\n\n<div id=\"one\"></div>\n<div id=\"two\"></div>\n<div id=\"three\"></div>\n"},{"desc":"Find the right answer! The fade will take 250 milliseconds and change various styles when it completes.","code":"\nvar getPos = function( n ) {\n return (Math.floor( n ) * 90) + \"px\";\n};\n$( \"p\" ).each(function( n ) {\n var r = Math.floor( Math.random() * 3 );\n var tmp = $( this ).text();\n $( this ).text( $( \"p:eq(\" + r + \")\" ).text() );\n $( \"p:eq(\" + r + \")\" ).text( tmp );\n $( this ).css( \"left\", getPos( n ) );\n});\n$( \"div\" )\n .each(function( n ) {\n $( this ).css( \"left\", getPos( n ) );\n })\n .css( \"cursor\", \"pointer\" )\n .click( function() {\n $( this ).fadeTo( 250, 0.25, function() {\n $( this )\n .css( \"cursor\", \"\" )\n .prev()\n .css({\n \"font-weight\": \"bolder\",\n \"font-style\": \"italic\"\n });\n });\n });\n","css":"\n div, p {\n width: 80px;\n height: 40px;\n top: 0;\n margin: 0;\n position: absolute;\n padding-top: 8px;\n }\n p {\n background: #fcc;\n text-align: center;\n }\n div {\n background: blue;\n }\n","html":"\n<p>Wrong</p>\n<div></div>\n<p>Wrong</p>\n<div></div>\n<p>Right!</p>\n<div></div>\n"}],"longdesc":"\n <p>The <code>.fadeTo()</code> method animates the opacity of the matched elements. It is similar to the <code><a href=\"/fadeIn/\">.fadeIn()</a></code> method but that method unhides the element and always fades to 100% opacity.</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. If any other string is supplied, the default duration of <code>400</code> milliseconds is used. Unlike the other effect methods, <code>.fadeTo()</code> requires that <code>duration</code> be explicitly specified.</p>\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>We can animate any element, such as a simple image:</p>\n <pre><code>\n&lt;div id=\"clickme\"&gt;\n Click here\n&lt;/div&gt;\n&lt;img id=\"book\" src=\"book.png\" alt=\"\" width=\"100\" height=\"123\"&gt;\n// With the element initially shown, we can dim it slowly:\n$( \"#clickme\" ).click(function() {\n $( \"#book\" ).fadeTo( \"slow\" , 0.5, function() {\n // Animation complete.\n });\n});\n </code></pre>\n <p class=\"image four-across\">\n <img src=\"/resources/0042_06_41.png\" alt=\"\"/>\n <img src=\"/resources/0042_06_42.png\" alt=\"\"/>\n <img src=\"/resources/0042_06_43.png\" alt=\"\"/>\n <img src=\"/resources/0042_06_44.png\" alt=\"\"/>\n </p>\n <p>With <code>duration</code> set to <code>0</code>, this method just changes the <code>opacity</code> CSS property, so <code>.fadeTo( 0, opacity )</code> is the same as <code>.css( \"opacity\", opacity )</code>.</p>\n "}]}