html - SVG 边框动画

标签 html css svg svg-animate

我找到了 this很酷的 SVG 边框动画,我试图将它应用到我的网站,但是我的网站包含不同大小的图像,因此动画受到宽度和高度的限制。

有什么方法可以编辑代码,以便我可以将此动画用于所有图像尺寸?

抱歉我的英语不好 :)

<svg width="200" height="200">
      <line class="top" x1="0" y1="0" x2="600" y2="0"/>
      <line class="left" x1="0" y1="200" x2="0" y2="-400"/>
      <line class="bottom" x1="200" y1="200" x2="-400" y2="200"/>
      <line class="right" x1="200" y1="0" x2="200" y2="600"/>
  </svg>

最佳答案

您可以使用简单的 CSS 和渐变,而不用担心容器或 img 的大小: DEMO

div, img {
  margin:1em;
  display:inline-block;
  padding:0.5em;
  vertical-align:top;
  border-radius:10px;
  background:linear-gradient(to left,black 33.33%,transparent 40% ,transparent 50%,black 66.66%) 0 0 repeat-x, linear-gradient(to right,black 33.33%,transparent 40% ,transparent 50%, black 66.66%) 100% 100%  repeat-x, linear-gradient(to top,black 33.33%,transparent 40% ,transparent 50%, black 66.66%) 0 100% repeat-y, linear-gradient(to bottom,black 33.33%,transparent 40% ,transparent 50%, black 66.66%) 100% 0 repeat-y, linear-gradient(to bottom right,turquoise,white,lime) center no-repeat ;
  background-color:gray;
  background-size:300% 5px,300% 5px,5px 300%,5px 300%,100% 100%;
  transition:1.5s linear; 
  }
div:hover { background-position:100% 0 ,0% 100%, 0 0 , 100% 100%, 0 0 ;}

可能的标记

<div>
  <h1> border transition</h1>
  <p>text</p>
</div>
<img src="http://lorempixel.com/200/150/"/>

关于html - SVG 边框动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23693547/

相关文章:

c# - html iFrame 内的 JQueryUI DatePicker 不会扩展到框架之外

javascript - Jquery Animate Image 在单击事件上向右,然后在第二次单击事件上返回到左侧

html - 如何使事件链接保持事件状态?

javascript - 我可以用javascript进行计划任务编程吗?

html - LESS 和 IE9 过滤器 :none for svg gradient compatibility?

html - 如果我为常见的 css 样式设置创建类并将它们分配给 html 元素,这是一个好习惯吗?

html - 防止div高度为 "0"

javascript - 如何使用angularjs动态调整窗口大小

css - 使用 SVG 符号隐藏渐变

css - Rect x 和 y 属性在 Firefox 中不起作用