尤明明Blog

网站建设外包|网站切图外包,技术不仅是一种专业,更是一种责任!

您的当前位置: 首页 » 前端学习 » css3+html5 »

分享一段页面加载完成前的SVG动画,纯代码实现!

2020-03-26   Umming   css3+html5    评论(0)    浏览(1997)


很多时候我们希望一个页面所有内容加载完成才展示出页面,逻辑很简单,就是给一个loader元素,页面加载完成使用window.load函数隐藏或者去掉loader元素,下面给大家分享一段纯代码打造的svg加载动画,建议移动端使用,因为svg动画对于pc浏览器兼容性不是太好,特别是ie,大家都懂的!

下面贴上代码,首先在body开始位置加入以下代码:

<style type="text/css">
.loader {position: fixed;top: 0;left: 0;right: 0;bottom:0;z-index: 99999;text-align: center;background:url(img/load_bg.png) #fff no-repeat center;background-size: cover }
.loader div{display: inline-block;color:#bca29b }
.loader svg path,.loadersvg rect {fill: #bca29b;}
	</style>
<div class="loader v-center">
  <div>
  	<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="24px" height="30px" viewBox="0 0 24 30"  xml:space="preserve">
    <rect x="0" y="8.24241" width="4" height="14.5152" fill="#bca29b">
      <animate attributeName="height" attributeType="XML" values="5;21;5" begin="0s" dur="0.6s" repeatCount="indefinite"></animate>
      <animate attributeName="y" attributeType="XML" values="13; 5; 13" begin="0s" dur="0.6s" repeatCount="indefinite"></animate>
    </rect>
    <rect x="10" y="12.2424" width="4" height="6.51518" fill="#bca29b">
      <animate attributeName="height" attributeType="XML" values="5;21;5" begin="0.15s" dur="0.6s" repeatCount="indefinite"></animate>
      <animate attributeName="y" attributeType="XML" values="13; 5; 13" begin="0.15s" dur="0.6s" repeatCount="indefinite"></animate>
    </rect>
    <rect x="20" y="9.75759" width="4" height="11.4848" fill="#bca29b">
      <animate attributeName="height" attributeType="XML" values="5;21;5" begin="0.3s" dur="0.6s" repeatCount="indefinite"></animate>
      <animate attributeName="y" attributeType="XML" values="13; 5; 13" begin="0.3s" dur="0.6s" repeatCount="indefinite"></animate>
    </rect>
  </svg>
  <p>资源加载中...</p>
  </div>
</div>

然后在页面底部加入加载事件即可

$(window).load(function (){$(".loader").remove() });

标签: svg动画

本文链接:https://www.umming.com/css3_html5/234.html     百度已收录

声明:本站信息由网友自行发布或来源于网络,真实性、合法性由发布人负责,请仔细甄别!本站只为传递信息,我们不做任何双方证明,也不承担任何法律责任。文章内容若侵犯你的权益,请联系本站删除!


发表评论: