• jquery动画效果


    显示于隐藏方法:

    1. DOCTYPE html>
    2. <html>
    3. <head>
    4. <meta charset="utf-8" />
    5. <meta name="viewport" content="width=device-width, initial-scale=1">
    6. <title>title>
    7. <script src="../jQuery3.6.0.js">script>
    8. <script>
    9. $(function() {
    10. $("#anniu").click(function() {
    11. if ($("#anniu").val() == "显示") {
    12. $("#img1").show("slow", function() {
    13. $("#img1").css({
    14. "border": "1px solid red",
    15. "background-color": "red"
    16. });
    17. });
    18. $("#anniu").val("隐藏");
    19. } else {
    20. $("#img1").hide("slow");
    21. $("#anniu").val("显示")
    22. }
    23. });
    24. });
    25. script>
    26. head>
    27. <body>
    28. <img style="display: none;" src="../img/3.png" id="img1" />
    29. <br/>
    30. <input type="button" value="显示" id="anniu" />
    31. body>
    32. html>

    多个参数时可以用“{}”包起来,用“,”隔开

     隐藏与显示之间切换:

    1. DOCTYPE html>
    2. <html>
    3. <head>
    4. <meta charset="utf-8" />
    5. <meta name="viewport" content="width=device-width, initial-scale=1">
    6. <title>title>
    7. <style>
    8. * {
    9. margin: 0px;
    10. padding: 0px;
    11. }
    12. body {
    13. font-size: 12px;
    14. }
    15. ul {
    16. list-style: none;
    17. }
    18. ul li {
    19. height: 30px;
    20. width: 100px;
    21. text-align: center;
    22. border: 1px solid paleturquoise;
    23. border-bottom: none;
    24. }
    25. ul li a {
    26. text-decoration: none;
    27. }
    28. ul li.img1 {
    29. background-image: url(../img/up.png);
    30. background-repeat: no-repeat;
    31. border-top: 1px solid paleturquoise;
    32. border-right: 0;
    33. }
    34. ul li.down{
    35. background-image: url(../img/end.png);
    36. }
    37. style>
    38. <script src="../jQuery3.6.0.js">script>
    39. <script>
    40. $(function(){
    41. $(".img1").click(function(){
    42. $("#div1 li:gt(5):not(:last)").fadeToggle();
    43. $(".img1").toggleClass("down");
    44. });
    45. });
    46. script>
    47. head>
    48. <body id="div1">
    49. <ul>
    50. <li><a href="#">9快9包邮a>li>
    51. <li><a href="#">大货精选a>li>
    52. <li><a href="#">海外海购a>li>
    53. <li><a href="#">大厂直销a>li>
    54. <li><a href="#">超值抢购a>li>
    55. <li><a href="#">家电办公a>li>
    56. <li><a href="#">母婴用品a>li>
    57. <li><a href="#">护肤美容a>li>
    58. <li><a href="#">手机数码a>li>
    59. <li><a href="#">户外运动a>li>
    60. <li><a href="#">家具家电a>li>
    61. <li class="img1">li>
    62. ul>
    63. body>
    64. html>

    fadeToggle方法会检测是否隐藏或显示,来回之间互相切换

    缓慢出现和缓慢隐藏:

    1. DOCTYPE html>
    2. <html>
    3. <head>
    4. <meta charset="utf-8" />
    5. <meta name="viewport" content="width=device-width, initial-scale=1">
    6. <title>title>
    7. <script src="../jQuery3.6.0.js">script>
    8. <script>
    9. $(function() {
    10. $("#anniu").click(function() {
    11. if ($("#anniu").val() == "显示") {
    12. $("#img1").fadeIn("slow", function() {
    13. $("#img1").css({
    14. "border": "1px solid red",
    15. "background-color": "red"
    16. });
    17. });
    18. $("#anniu").val("隐藏");
    19. } else {
    20. $("#img1").fadeOut("slow");
    21. $("#anniu").val("显示")
    22. }
    23. });
    24. });
    25. script>
    26. head>
    27. <body>
    28. <img style="display: none;" src="../img/3.png" id="img1" />
    29. <br/>
    30. <input type="button" value="显示" id="anniu" />
    31. body>
    32. html>

    通过下拉框改变透明度:

    1. DOCTYPE html>
    2. <html>
    3. <head>
    4. <meta charset="utf-8" />
    5. <meta name="viewport" content="width=device-width, initial-scale=1">
    6. <title>title>
    7. <script src="../jQuery3.6.0.js">script>
    8. <script>
    9. $(function(){
    10. $("#sel").change(function(){
    11. var date=$("#sel").val();
    12. $("#img").fadeTo(1000,date);
    13. });
    14. });
    15. script>
    16. head>
    17. <body>
    18. <img src="../img/ys.png" id="img"/>
    19. <select id="sel">
    20. <option value="0.2">0.2option>
    21. <option value="0.4">0.4option>
    22. <option value="0.6">0.6option>
    23. <option value="0.8">0.8option>
    24. <option value="1" selected="selected">1option>
    25. select>
    26. body>
    27. html>

    鼠标悬浮、点击:显示、隐藏:

    1. DOCTYPE html>
    2. <html>
    3. <head>
    4. <meta charset="utf-8" />
    5. <meta name="viewport" content="width=device-width, initial-scale=1">
    6. <title>title>
    7. <style>
    8. * {
    9. margin: 0px;
    10. padding: 0px;
    11. }
    12. #ul1 {
    13. list-style: none;
    14. }
    15. #ul1 li {
    16. width: 120px;
    17. float: left;
    18. margin-left: 20px;
    19. }
    20. #ul1 li ul li {
    21. width: 100px;
    22. float: none;
    23. list-style: none;
    24. border: 1px solid red;
    25. display: none;
    26. }
    27. style>
    28. <script src="../jQuery3.6.0.js">script>
    29. <script>
    30. $(function() {
    31. //点击显示、隐藏
    32. // $("#rmyy").click(function(){
    33. // $("#rmyy ul li").stop(true,false).slideToggle(250);
    34. // });
    35. $("#rmyy").hover(function() {
    36. $("#rmyy ul li").slideDown(250);
    37. }, function() {
    38. $("#rmyy ul li").stop(true, false).slideUp(250);
    39. });
    40. });
    41. script>
    42. head>
    43. <body>
    44. <ul id="ul1">
    45. <li id="rmyy"><a href="#">热门音乐a>
    46. <ul>
    47. <li><a href="#">江南stala>li>
    48. <li>错错错li>
    49. <li>御剑飞行li>
    50. ul>
    51. li>
    52. <li>我的音乐li>
    53. <li>联系商家li>
    54. <li>我的VIPli>
    55. ul>
    56. body>
    57. html>

    自定义动画:

    1. DOCTYPE html>
    2. <html>
    3. <head>
    4. <meta charset="utf-8" />
    5. <meta name="viewport" content="width=device-width, initial-scale=1">
    6. <title>title>
    7. <script src="../jQuery3.6.0.js">script>
    8. <script>
    9. $(function() {
    10. $("#img1").click(function() {
    11. $(this).animate({
    12. width: "500px"
    13. }, "slow");
    14. $(this).animate({
    15. height: "200px"
    16. }, "slow");
    17. $(this).animate({
    18. width: "200px"
    19. }, "slow");
    20. $(this).animate({
    21. height: "50px"
    22. }, "slow");
    23. });
    24. });
    25. script>
    26. head>
    27. <body id="div1">
    28. <img src="../img/3.png" id="img1" />
    29. body>
    30. html>

    利用animate方法

     

    1. DOCTYPE html>
    2. <html>
    3. <head>
    4. <meta charset="utf-8" />
    5. <meta name="viewport" content="width=device-width, initial-scale=1">
    6. <title>title>
    7. <script src="../jQuery3.6.0.js">script>
    8. <script>
    9. $(function() {
    10. $("#img1").click(function() {
    11. $(this).animate({left:"+=100px",top:"+=100px",opacity:0.5},3000);
    12. });
    13. });
    14. script>
    15. <style>
    16. #img1{
    17. position: absolute;
    18. }
    19. style>
    20. head>
    21. <body id="div1">
    22. <img src="../img/3.png" id="img1" />
    23. body>
    24. html>

     移动位置前要将位置改为绝对定位

        position: absolute;

  • 相关阅读:
    FileChannel 文件流的简单使用
    ActiveMQ、RabbitMQ、Kafka、RocketMQ在事务性消息、性能、高可用和容错、定时消息、负载均衡、刷盘策略的区别
    Codeforces Round #805 (Div. 3)总结
    vue3+scss开启写轮眼
    hadoop-2.6.4集群编译搭建-阿里云和腾讯云
    Figure 02 机器人发布:未来AI的巅峰还是泡沫中的救命稻草?
    VMware ubuntu空间越用越大
    【SpringMVC】RESTFul风格设计和实战 第三期
    鸿蒙 Harmony 的跨端技术方案
    mybatis关联关系映射
  • 原文地址:https://blog.csdn.net/qx020814/article/details/126033318