首页 > 代码库 > 2017-6-2 jQuery 动画
2017-6-2 jQuery 动画
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <script src=http://www.mamicode.com/"js/jquery-1.7.1.min.js"></script> <title></title> <style type="text/css"> .div1 { width:200px; height:200px; background-color:red; float:left; margin:20px 20px; } </style> </head> <body> <input type="button" value=http://www.mamicode.com/"btn1" id="btn1" /> <div class="div1"></div> <div class="div1"></div> </body> </html> <script type="text/javascript"> //隐藏显示: $("#btn1").click(function () { if ($(".div1").css(‘display‘) == ‘block‘) { $(".div1").hide(); } else { $(".div1").show(); } }); //卷帘门效果: $("#btn1").click(function () { if ($(".div1").css(‘display‘) == ‘block‘) { $(".div1").slideUp(); } else { $(".div1").slideDown(); } }); // 淡入淡出效果: $("#btn1").click(function () { if ($(".div1").css(‘display‘) == ‘block‘) { $(".div1").fadeOut(); } else { $(".div1").fadeIn(); } }); //自定义动画: $("#btn1").click(function () { $(".div1").animate({width:"500px",height:"800"},1000); }); </script>
下拉菜单:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <script src=http://www.mamicode.com/"js/jquery-1.7.1.min.js"></script> <title></title> <style type="text/css"> .div1 { position:relative; width:100px; height:50px; background-color:red; float:left; margin-left:20px; } .div2 { position:absolute; width:100%; height:0px; top:50px; background-color:green; } </style> </head> <body> <div class="div1"> <div class="div2"></div> </div> <div class="div1"> <div class="div2"></div> </div> <div class="div1"> <div class="div2"></div> </div> <div class="div1"> <div class="div2"></div> </div> <div class="div1"> <div class="div2"></div> </div> </body> </html> <script type="text/javascript"> $(".div1").mousemove(function () { var aa = $(this).children(".div2:eq(0)"); aa.stop().animate({ height: "300px" }, 100, function () { aa.css("background-color","blue"); }); }); $(".div1").mouseout(function () { var aaa = $(this).children(".div2:eq(0)"); aaa.stop().animate({ height: "0px" }, 100, function () { aaa.css("background-color", "yellow"); }); }); </script>
淡入淡出按钮效果:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <script src=http://www.mamicode.com/"js/jquery-1.7.1.min.js"></script> <script src=http://www.mamicode.com/"js/jquery.color.js"></script> <title></title> <style type="text/css"> #div1 { width:200px; height:200px; background-color:red; font-size:30px; } </style> </head> <body> <form id="form1" runat="server"> <div id="div1">按钮 </div> </form> </body> </html> <script type="text/javascript"> $("#div1").mousemove(function () { $(this).animate({backgroundColor:"green", color:"white"},500); }); $("#div1").mouseout(function () { $(this).animate({ backgroundColor: "red", color: "black" }, 500); }); </script>
2017-6-2 jQuery 动画
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。