Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

小技巧分享 #4

Closed
bosens-China opened this issue Aug 7, 2019 · 0 comments
Closed

小技巧分享 #4

bosens-China opened this issue Aug 7, 2019 · 0 comments
Labels
框架相关 目前Vue和React为主

Comments

@bosens-China
Copy link
Owner

bosens-China commented Aug 7, 2019

loading

为了避免白屏时间过长,通过会给一个动画来提示用户正在加载,下面就是简单说下在Vue加载之前如何实现动画效果

原理

在初始化Vue的时候我们需要提供一个节点或者节点名称,作为根元素来使用,但是这个根元素在new Vue执行的时候内容会被销毁,不信来测试一个例子

<div id="app">
  hello wrold
</div>
// 省略
new Vue({
  el: "#app"
});

可以复制一下上面代码,当上面代码执行的时候,#app下的内容会被清空,根据这个思路就很容易实现我们想要的效果了

实现简单一版

<div id="app">正在加载中<dot>...</dot></div>
dot {
  display: inline-block;
  height: 1em;
  line-height: 1;
  text-align: left;
  vertical-align: -0.25em;
  overflow: hidden;
}
dot::before {
  display: block;
  content: "...\A..\A.";
  white-space: pre-wrap;
  animation: dot 3s infinite step-start both;
}
@keyframes dot {
  33% {
    transform: translateY(-2em);
  }
  66% {
    transform: translateY(-1em);
  }
}

这样就实现了一个简单的动画效果了

@bosens-China bosens-China added the 框架相关 目前Vue和React为主 label Aug 7, 2019
@bosens-China bosens-China changed the title 为vue开场添加一个loading 如果开场添加一个loading动画 Sep 27, 2019
@bosens-China bosens-China changed the title 如果开场添加一个loading动画 如何在Vue加载前添加一个loading动画 Sep 27, 2019
@bosens-China bosens-China changed the title 如何在Vue加载前添加一个loading动画 如何在Vue加载前添加一个loading动画? Sep 27, 2019
@bosens-China bosens-China changed the title 如何在Vue加载前添加一个loading动画? loading动画实现思路 Dec 18, 2019
@bosens-China bosens-China changed the title loading动画实现思路 小技巧分享 Dec 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
框架相关 目前Vue和React为主
Projects
None yet
Development

No branches or pull requests

1 participant