用jQuery完成淡入淡出效果前,我们先来认识几个代码:
- 淡入 fadeIn([ speed , [easing] , [fn] ]),参数都可不写
- 淡出 fadeOut([ speed , [easing] , [fn] ]),参数都可不写
- 淡入淡出切换 fadeToggle([ speed , [easing] , [fn] ]),参数都可不写
- 修改透明度 fadeTo([ [speed] , opacity , [easing] , [fn] ]),注意,这里速度和透明度一定要写
其中
- speed是速度
- easing是切换效果
- fn是回调函数
那我们把上述代码放到整体代码中看下效果
完整代码如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | <!DOCTYPE html> < html lang = "en" > < head > < meta charset = "UTF-8" > < title >Wellfancy</ title > < style > div { margin: 10px; padding: 10px; width: 100px; display: none; } </ style > </ head > < body > < button >淡入效果</ button > < button >淡出效果</ button > < button >淡入淡出切换</ button > < button >修改透明度</ button > < div > < img src = "images/1.jpg" style = "width: 280px;" > </ div > < script > $(function() { $("button").eq(0).click(function() { $("div").fadeIn(1000); }) $("button").eq(1).click(function() { $("div").fadeOut(1000); }) $("button").eq(2).click(function() { $("div").fadeToggle(1000); }); $("button").eq(3).click(function() { $("div").fadeTo(1000, 0.5); }); }); </ script > </ body > </ html > |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持自学编程网。
- 本文固定链接: https://zxbcw.cn/post/219093/
- 转载请注明:必须在正文中标注并保留原文链接
- QQ群: PHP高手阵营官方总群(344148542)
- QQ群: Yii2.0开发(304864863)