animation.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * 创建者:王成
  3. * 创建日期:2022年4月15日
  4. * 描述:动画脚本
  5. * 要求:该脚本需要JQuery脚本的支持,请提前引入
  6. */
  7. function appendBorderAnimation(className) {
  8. /* 根据类名称组合选择器 */
  9. var selector = "." + className;
  10. /* 各元素添加必须属性 */
  11. $(selector).css("overflow", "hidden");
  12. /* 获取元素的宽度和高度 */
  13. var width = $(selector).width();
  14. var height = $(selector).height();
  15. console.log("宽度=" + width + " 高度=" + height);
  16. /* 添加边框div */
  17. var domBorder = document.createElement('div');
  18. $(selector).prepend(domBorder);
  19. /* 添加内容div */
  20. var domContent = document.createElement('div');
  21. $(selector).prepend(domContent);
  22. /* 设置边框样式 */
  23. var childBorder = "." + className + " >div:nth-child(1)";
  24. $(childBorder).css("position", "relative");
  25. $(childBorder).css("width", "0");
  26. $(childBorder).css("height", "0");
  27. $(childBorder).css("border-top", height + "px solid green");
  28. $(childBorder).css("border-right", width + "px solid rgba(255,255,255,0)");
  29. $(childBorder).css("border-bottom", height + "px solid green");
  30. $(childBorder).css("border-left", width + "px solid rgba(255,255,255,0)");
  31. $(childBorder).css("left", "-" + width / 2 + "px");
  32. $(childBorder).css("top", "-" + height / 2 + "px");
  33. $(childBorder).css("animation", "rotate 5s linear infinite");
  34. /* 设置内容样式 */
  35. var childContent = "." + className + " >div:nth-child(2)";
  36. $(childContent).css("position", "absolute");
  37. $(childContent).css("top", "4px");
  38. $(childContent).css("right", "4px");
  39. $(childContent).css("bottom", "4px");
  40. $(childContent).css("left", "4px");
  41. $(childContent).css("background-color", "rgba(128,128,128,0)");
  42. }
  43. function appendLineAnimation(className) {
  44. /* 根据类名称组合选择器 */
  45. var selector = "." + className;
  46. /* 获取元素的宽度和高度 */
  47. var width = $(selector).width();
  48. var height = $(selector).height();
  49. /* 修改变量 */
  50. document.documentElement.style.setProperty('--width', (parseInt(width) + 20) + 'px');
  51. document.documentElement.style.setProperty('--left', (parseInt(width) - 2) + 'px');
  52. document.documentElement.style.setProperty('--height', (parseInt(height) + 20) + 'px');
  53. document.documentElement.style.setProperty('--bottom', (parseInt(height) - 2) + 'px');
  54. /* 添加属性 */
  55. var css = "<style>" + selector + "::before," + selector + "::after{";
  56. css += "position: absolute;";
  57. css += "top: 0;";
  58. css += "bottom: 0;";
  59. css += "left: 0;";
  60. css += "right: 0;";
  61. css += "content: '';";
  62. // css += "z-index: -1;";
  63. css += "margin: -6px;";
  64. css += "box-shadow: inset 0 0 0 2px;";
  65. css += "-webkit-animation: clipMe 8s linear infinite ;";
  66. css += "}</style>";
  67. $(selector).append(css);
  68. $(selector).append("<style>" + selector +"::before{-webkit-animation-delay: -4s;}</style>");
  69. }