在现在的网页建设中效果是非常常用的。 比如说当你鼠标移动到某个地方的时候出现的提示。 当你鼠标点击的时候一些切换的效果。 我相信每个人都不能没有注意这些特效。 因为有了这些效果才能使我们的网页更加的美观,功能更加的丰富。 掌握效果的使用也是非常基础而且有必要的基础课程。
1.显示和隐藏。
2.淡入淡出
3.移动
4.动画
显示和隐藏是最基本的效果了。 而且是随处可见的。例如csdn的首页的
很典型的一个例子。
仿照网易邮箱记住密码做的。 主要使用hide和show方法 和html中设置style可见度是一个道理。
<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/html"> <head> <script src="js/jquery-1.11.0.min.js"></script> <script> $(document).ready(function () { $("div").mouseenter(function () { $("#info").show(); }) $("div").mouseleave(function () { $("#info").hide(); }) }) </script> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div align="center"> <input type="checkbox" value="一周内免登陆"/><span>一周内免登陆</span> </div> <p id="info" align="center" style="display: none">xxxxxxxxxxxxxxxxxx</p> </body> </html>也算是一种显示和隐藏功能,但是可以设置显示和隐藏的速度和透明度。
和上述的例子基本相同。 只要替换函数名即可。
1.fadeIn和fadeOut
<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/html"> <head> <script src="js/jquery-1.11.0.min.js"></script> <script> $(document).ready(function () { $("div").mouseenter(function () { $("#info").fadeIn(1000); }) $("div").mouseleave(function () { $("#info").fadeOut(1000); }) }) </script> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div align="center"> <input type="checkbox" value="一周内免登陆"/><span>一周内免登陆</span> </div> <p id="info" align="center" style="display: none">xxxxxxxxxxxxxxxxxx</p> </body> </html>2.fadeToggle
<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/html"> <head> <style> .div { width: 100px; height: auto; margin-right: auto; margin-left: auto; } .div .div-top { height: 100px; background-color: #049f3a; } .div .div-bottom { background-color: aqua; height: 200px; } </style> <script src="js/jquery-1.11.0.min.js"></script> <script> $(document).ready(function () { $(".div-top").click(function () { $(".div-bottom").toggle(1000); }); }); </script> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div class="div" align="center"> <div class="div-top">点击我测试</div> <div class="div-bottom"></div> </div> </body> </html>3.dadeto
<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/html"> <head> <style> .div { width: 100px; height: auto; margin-right: auto; margin-left: auto; } .div .div-top { height: 100px; background-color: #049f3a; } .div .div-bottom { background-color: aqua; height: 200px; } </style> <script src="js/jquery-1.11.0.min.js"></script> <script> $(document).ready(function () { $(".div-top").click(function () { $(".div-bottom").fadeTo(1000,0.5); }); }); </script> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div class="div" align="center"> <div class="div-top">点击我测试</div> <div class="div-bottom"></div> </div> </body> </html>通过移动效果其实和消失移动的功能和和相似。
在原来的效果之上加上对属性的一些操作使得如同动画一般。
animate({params},speed,callback) //属性集合,速度和回调函数
很多效果都需要自己去操作,试着模仿网站中的一些效果。 我相信主要尝试肯定可以成功。
相关资源:JQuery zTree v3.1