经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » JS/JS库/框架 » JavaScript » 查看文章
vuejs怎样封装一个插件(以封装vue-toast为例扩展)
来源:cnblogs  作者:风雨后见彩虹  时间:2021/2/18 16:32:01  对本文有异议

插件介绍

插件通常会为 Vue 添加全局功能。插件的范围没有限制——一般有下面几种:

  • 1.添加全局方法或者属性,如: vue-custom-element
  • 2.添加全局资源:指令/过滤器/过渡等,如 vue-touch
  • 3.通过全局 mixin 方法添加一些组件选项,如: vue-router
  • 4.添加 Vue 实例方法,通过把它们添加到 Vue.prototype 上实现。
  • 5.一个库,提供自己的 API,同时提供上面提到的一个或多个功能,如 vue-router

Vue.js 的插件应当有一个公开方法 install 。这个方法的第一个参数是 Vue 构造器,第二个参数是一个可选的选项对象:

  1. MyPlugin.install = function (Vue, options) {
  2. // 1. 添加全局方法或属性
  3. Vue.myGlobalMethod = function () {
  4. // 逻辑...
  5. }
  6. // 2. 添加全局资源
  7. Vue.directive('my-directive', {
  8. bind (el, binding, vnode, oldVnode) {
  9. // 逻辑...
  10. }
  11. ...
  12. })
  13. // 3. 注入组件
  14. Vue.mixin({
  15. created: function () {
  16. // 逻辑...
  17. }
  18. ...
  19. })
  20. // 4. 添加实例方法
  21. Vue.prototype.$myMethod = function (methodOptions) {
  22. // 逻辑...
  23. }
  24. }

使用方式很简单,通过全局方法Vue.use()来使用插件。

下面开发一个简单的在控制台打印消息插件,新建一个toast.js:

  1. var Toast = {};
  2. Toast.install = function (Vue, options) {
  3. Vue.prototype.$msg = 'Hello World';
  4. }
  5. export default Toast;

在main.js中引入该toast.js并使用vue.use()安装该toast插件:

  1. import Vue from 'vue';
  2. import Toast from './toast.js';
  3. Vue.use(Toast);

然后我们在任意vue页面就可以调用:

  1. export default {
  2. mounted(){
  3. console.log(this.$msg); // Hello World
  4. }
  5. }

 开发vue-toast插件

该插件实现的效果:

  • 1.提示内容可以显示在不同的位置(顶部、底部、中间),调用方式this.$toast.top('填写的提示内容')this.$toast.center('填写的提示内容')this.$toast.bottom('填写的提示内容')
  • 2.通过this.$toast('填写的提示内容')调用该插件,默认展示在底部;
  • 3.toast有默认的展示持续时间,也可配置toast展示的持续时间。

toast.js实现代码如下:

  1. let Toast = {};
  2. Toast.install = function(Vue,options) {
  3. let opts = {
  4. type: 'bottom', // 显示位置
  5. duration: 2500 // 持续时间
  6. }
  7. for(let prop in options) {
  8. if(options.hasOwnProperty(prop)) {
  9. opts[prop] = options[prop];
  10. }
  11. }
  12. Vue.prototype.$toast = (tips,type) => {
  13. if(type) {
  14. opts.type = type;
  15. }
  16. if(document.getElementsByClassName('vue-toast').length) {
  17. return false;
  18. }
  19. let ToastEl = Vue.extend({
  20. template: `<div class="vue-toast vue-toast__${opts.type}">${tips}</div>`
  21. })
  22. let toastElement = new ToastEl().$mount().$el;
  23. document.body.append(toastElement);
  24. setTimeout(() => {
  25. document.body.removeChild(toastElement);
  26. },opts.duration);
  27. }
  28. ['top','center','bottom'].forEach((type) => {
  29. Vue.prototype.$toast[type] = (tips) => {
  30. return Vue.prototype.$toast(tips,type)
  31. }
  32. })
  33. }
  34. export default Toast;

 优化vue-toast

调用方式更通用,如下所示:

  1. this.toast = this.$toast({
  2. message: '这是一段信息',
  3. position: 'top',
  4. duration: 0
  5. });

可以手动关闭弹框

  1. this.toast.close();

实现方式就是封装成一个构造函数,整体代码如下:

  1. function Toast() {
  2. this.toastTimer = false; // toastTimer:toast定时器
  3. this.toastVM = null; // toastVM:存储toast VM
  4. this.install = function(Vue,options) {
  5. let opts = {
  6. message: '', // 文本内容
  7. position: 'bottom', // 显示位置
  8. duration: 2500, // 展示时长(ms),值为 0 时,toast 不会消失
  9. className: '' // 自定义类名
  10. }
  11. /** toast提示方法
  12. * @params {Object|String} config 配置,如果为字符串=message
  13. * */
  14. Vue.prototype.$toast = (config) => {
  15. let option = {};
  16. let self = this;
  17. Object.assign(option,opts,options);
  18. if(typeof config === 'object') {
  19. Object.assign(option,config)
  20. } else { // 如果是字符串,传递的是message文本内容
  21. option.message = config;
  22. }
  23. if(this.toastTimer) { // 如果toast还在,则取消上次消失时间
  24. clearTimeout(this.toastTimer);
  25. this.toastVM.show = false;
  26. }
  27. if(!this.toastVM) {
  28. let ToastEl = Vue.extend({
  29. data() {
  30. return {
  31. show: false,
  32. message: option.message,
  33. className: option.className
  34. }
  35. },
  36. methods: {
  37. // 关闭toast
  38. close() {
  39. self.toastVM.show = false;
  40. }
  41. },
  42. render(createElement) {
  43. if(!this.show) {
  44. return false;
  45. }
  46. return createElement(
  47. 'div',
  48. {
  49. class: ['lx-toast',`lx-toast-${option.position}`,this.className],
  50. show: this.show,
  51. domProps: {
  52. innerHTML: this.message
  53. }
  54. },
  55. )
  56. }
  57. })
  58. this.toastVM = new ToastEl();
  59. document.body.append(this.toastVM.$mount().$el);
  60. }
  61. this.toastVM.show = true;
  62. this.toastVM.message = option.message;
  63. this.toastVM.className = option.className;
  64. this.toastVM.position = option.position;
  65. if(option.duration != 0) {// 为0的时候一直显示
  66. this.toastTimer = setTimeout(() => {
  67. this.toastVM.show = this.toastTimer = false;
  68. },option.duration)
  69. }
  70. return this.toastVM;
  71. }
  72. }
  73. }
  74. export default new Toast();

使用方式:

  1. <template>
  2. <div class="test">
  3. <button @click="open">开启弹框</button>
  4. <button @click="close">关闭弹框</button>
  5. </div>
  6. </template>
  7.  
  8. <script>
  9. export default {
  10. data () {
  11. return {
  12. toast: null
  13. }
  14. },
  15. methods: {
  16. open() {
  17. this.toast = this.$toast({
  18. message: '这是一段信息',
  19. position: 'top',
  20. duration: 0
  21. });
  22. },
  23. close() {
  24. this.toast.close();
  25. }
  26. }
  27. }
  28. </script>

添加loading方法

完整代码:

  1. function Toast() {
  2. this.toastTimer = false; // toastTimer:toast定时器
  3. this.toastVM = null; // toastVM:存储toast VM
  4. this.showLoad = false; // 存储loading显示状态
  5. this.loadNode = null; // 存储loading节点元素
  6. this.install = function(Vue,options) {
  7. let opts = {
  8. message: '', // 文本内容
  9. position: 'bottom', // 显示位置
  10. duration: 2500, // 展示时长(ms),值为 0 时,toast 不会消失
  11. className: '' // 自定义类名
  12. }
  13. /** toast提示方法
  14. * @params {Object|String} config 配置,如果为字符串=message
  15. * */
  16. Vue.prototype.$toast = (config) => {
  17. let option = {};
  18. let self = this;
  19. Object.assign(option,opts,options);
  20. if(typeof config === 'object') {
  21. Object.assign(option,config)
  22. } else { // 如果是字符串,传递的是message文本内容
  23. option.message = config;
  24. }
  25. if(this.toastTimer) { // 如果toast还在,则取消上次消失时间
  26. clearTimeout(this.toastTimer);
  27. this.toastVM.show = false;
  28. }
  29. if(!this.toastVM) {
  30. let ToastEl = Vue.extend({
  31. data() {
  32. return {
  33. show: false,
  34. message: option.message,
  35. className: option.className
  36. }
  37. },
  38. methods: {
  39. // 关闭toast
  40. close() {
  41. self.toastVM.show = false;
  42. }
  43. },
  44. render(createElement) {
  45. if(!this.show) {
  46. return false;
  47. }
  48. return createElement(
  49. 'div',
  50. {
  51. class: ['lx-toast',`lx-toast-${option.position}`,this.className],
  52. show: this.show,
  53. domProps: {
  54. innerHTML: this.message
  55. }
  56. },
  57. )
  58. }
  59. })
  60. this.toastVM = new ToastEl();
  61. document.body.append(this.toastVM.$mount().$el);
  62. }
  63. this.toastVM.show = true;
  64. this.toastVM.message = option.message;
  65. this.toastVM.className = option.className;
  66. this.toastVM.position = option.position;
  67. if(option.duration != 0) {// 为0的时候一直显示
  68. this.toastTimer = setTimeout(() => {
  69. this.toastVM.show = this.toastTimer = false;
  70. },option.duration)
  71. }
  72. return this.toastVM;
  73. }
  74. /** $loading加载
  75. * @params {Object|String} config 配置,如果为字符串=message
  76. * */
  77. Vue.prototype.$loading = (config) => {
  78. let option = {};
  79. let self = this;
  80. if(typeof config === 'object') {
  81. Object.assign(option,config)
  82. } else { // 传递的字符串
  83. option.message = config;
  84. }
  85. if(option.type == 'close') {
  86. if(this.loadNode) {
  87. this.loadNode.show = this.showLoad = false;
  88. }
  89. } else {
  90. if(this.showLoad && this.loadNode) {
  91. this.loadNode.message = option.message;
  92. return false;
  93. }
  94. const loadEl = Vue.extend({
  95. data() {
  96. return {
  97. show: false,
  98. message: option.message
  99. }
  100. },
  101. methods: {
  102. close() {
  103. self.loadNode.show = self.showLoad = false;
  104. }
  105. },
  106. render(h) {
  107. if(!this.show) {
  108. return false;
  109. }
  110. return h('div',{
  111. class: 'lx-load-mark',
  112. show: this.show
  113. },[
  114. h('div',{
  115. class: 'lx-load-box'
  116. },[
  117. h('div',{
  118. class: this.message ? 'lx-loading':'lx-loading-nocontent'
  119. },Array.apply(null,{length: 12}).map((value,index) => {
  120. return h('div',{
  121. class: ['loading_leaf',`loading_leaf_${index}`]
  122. })
  123. })),
  124. h('div',{
  125. class: 'lx-load-content',
  126. domProps: {
  127. innerHTML: this.message
  128. }
  129. })
  130. ])
  131. ])
  132. }
  133. })
  134. this.loadNode = new loadEl();
  135. document.body.appendChild(this.loadNode.$mount().$el);
  136. this.loadNode.show = this.showLoad = true;
  137. }
  138. return this.loadNode;
  139. }
  140. ['open','close'].forEach(type => {
  141. Vue.prototype.$loading[type] = (message) => {
  142. return Vue.prototype.$loading({type,message})
  143. }
  144. })
  145. }
  146. }
  147. export default new Toast();

完整的调用方式:

  1. <template>
  2. <div class="test">
  3. <button @click="open">开启弹框</button>
  4. <button @click="close">关闭弹框</button>
  5. </div>
  6. </template>
  7.  
  8. <script>
  9. export default {
  10. data () {
  11. return {
  12. toast: null
  13. }
  14. },
  15. mounted() {
  16. let loading = this.$loading({
  17. message: '这是loading文字'
  18. })
  19. setTimeout(() => { // 5s 后关闭弹框
  20. loading.close();
  21. },5000);
  22. },
  23. methods: {
  24. open() {
  25. this.toast = this.$toast({
  26. message: '这是一段信息',
  27. position: 'top',
  28. duration: 0
  29. });
  30. },
  31. close() {
  32. this.toast.close();
  33. }
  34. }
  35. }
  36. </script>

 toast.css代码:

  1. .lx-toast {
  2. position: fixed;
  3. bottom: 100px;
  4. left: 50%;
  5. -webkit-box-sizing: border-box;
  6. box-sizing: border-box;
  7. max-width: 80%;
  8. height: 40px;
  9. line-height: 20px;
  10. padding: 10px 20px;
  11. transform: translateX(-50%);
  12. -webkit-transform: translateX(-50%);
  13. text-align: center;
  14. z-index: 9999;
  15. font-size: 14px;
  16. color: #fff;
  17. border-radius: 5px;
  18. background: rgba(0, 0, 0, 0.7);
  19. animation: show-toast .5s;
  20. -webkit-animation: show-toast .5s;
  21. overflow: hidden;
  22. text-overflow: ellipsis;
  23. white-space: nowrap;
  24. }
  25. .lx-toast.lx-word-wrap {
  26. width: 80%;
  27. white-space: inherit;
  28. height: auto;
  29. }
  30. .lx-toast.lx-toast-top {
  31. top: 50px;
  32. bottom: inherit;
  33. }
  34. .lx-toast.lx-toast-center {
  35. top: 50%;
  36. margin-top: -20px;
  37. bottom: inherit;
  38. }
  39. @-webkit-keyframes show-toast {
  40. from {
  41. opacity: 0;
  42. }
  43. to {
  44. opacity: 1;
  45. }
  46. }
  47. @keyframes show-toast {
  48. from {
  49. opacity: 0;
  50. }
  51. to {
  52. opacity: 1;
  53. }
  54. }
  55. .lx-load-mark {
  56. position: fixed;
  57. left: 0;
  58. top: 0;
  59. width: 100%;
  60. height: 100%;
  61. z-index: 9999;
  62. }
  63. .lx-load-box {
  64. position: fixed;
  65. z-index: 3;
  66. width: 7.6em;
  67. min-height: 7.6em;
  68. top: 180px;
  69. left: 50%;
  70. margin-left: -3.8em;
  71. background: rgba(0, 0, 0, 0.7);
  72. text-align: center;
  73. border-radius: 5px;
  74. color: #FFFFFF;
  75. }
  76. .lx-load-content {
  77. margin-top: 64%;
  78. font-size: 14px;
  79. }
  80. .lx-loading, .lx-loading-nocontent {
  81. position: absolute;
  82. width: 0px;
  83. left: 50%;
  84. top: 38%;
  85. }
  86. .lx-loading-nocontent {
  87. top: 50%;
  88. }
  89. .loading_leaf {
  90. position: absolute;
  91. top: -1px;
  92. opacity: 0.25;
  93. }
  94. .loading_leaf:before {
  95. content: " ";
  96. position: absolute;
  97. width: 9.14px;
  98. height: 3.08px;
  99. background: #d1d1d5;
  100. -webkit-box-shadow: rgba(0, 0, 0, 0.0980392) 0px 0px 1px;
  101. box-shadow: rgba(0, 0, 0, 0.0980392) 0px 0px 1px;
  102. border-radius: 1px;
  103. -webkit-transform-origin: left 50% 0px;
  104. transform-origin: left 50% 0px;
  105. }
  106. .loading_leaf_0 {
  107. -webkit-animation: opacity-0 1.25s linear infinite;
  108. animation: opacity-0 1.25s linear infinite;
  109. }
  110. .loading_leaf_0:before {
  111. -webkit-transform: rotate(0deg) translate(7.92px, 0px);
  112. transform: rotate(0deg) translate(7.92px, 0px);
  113. }
  114. .loading_leaf_1 {
  115. -webkit-animation: opacity-1 1.25s linear infinite;
  116. animation: opacity-1 1.25s linear infinite;
  117. }
  118. .loading_leaf_1:before {
  119. -webkit-transform: rotate(30deg) translate(7.92px, 0px);
  120. transform: rotate(30deg) translate(7.92px, 0px);
  121. }
  122. .loading_leaf_2 {
  123. -webkit-animation: opacity-2 1.25s linear infinite;
  124. animation: opacity-2 1.25s linear infinite;
  125. }
  126. .loading_leaf_2:before {
  127. -webkit-transform: rotate(60deg) translate(7.92px, 0px);
  128. transform: rotate(60deg) translate(7.92px, 0px);
  129. }
  130. .loading_leaf_3 {
  131. -webkit-animation: opacity-3 1.25s linear infinite;
  132. animation: opacity-3 1.25s linear infinite;
  133. }
  134. .loading_leaf_3:before {
  135. -webkit-transform: rotate(90deg) translate(7.92px, 0px);
  136. transform: rotate(90deg) translate(7.92px, 0px);
  137. }
  138. .loading_leaf_4 {
  139. -webkit-animation: opacity-4 1.25s linear infinite;
  140. animation: opacity-4 1.25s linear infinite;
  141. }
  142. .loading_leaf_4:before {
  143. -webkit-transform: rotate(120deg) translate(7.92px, 0px);
  144. transform: rotate(120deg) translate(7.92px, 0px);
  145. }
  146. .loading_leaf_5 {
  147. -webkit-animation: opacity-5 1.25s linear infinite;
  148. animation: opacity-5 1.25s linear infinite;
  149. }
  150. .loading_leaf_5:before {
  151. -webkit-transform: rotate(150deg) translate(7.92px, 0px);
  152. transform: rotate(150deg) translate(7.92px, 0px);
  153. }
  154. .loading_leaf_6 {
  155. -webkit-animation: opacity-6 1.25s linear infinite;
  156. animation: opacity-6 1.25s linear infinite;
  157. }
  158. .loading_leaf_6:before {
  159. -webkit-transform: rotate(180deg) translate(7.92px, 0px);
  160. transform: rotate(180deg) translate(7.92px, 0px);
  161. }
  162. .loading_leaf_7 {
  163. -webkit-animation: opacity-7 1.25s linear infinite;
  164. animation: opacity-7 1.25s linear infinite;
  165. }
  166. .loading_leaf_7:before {
  167. -webkit-transform: rotate(210deg) translate(7.92px, 0px);
  168. transform: rotate(210deg) translate(7.92px, 0px);
  169. }
  170. .loading_leaf_8 {
  171. -webkit-animation: opacity-8 1.25s linear infinite;
  172. animation: opacity-8 1.25s linear infinite;
  173. }
  174. .loading_leaf_8:before {
  175. -webkit-transform: rotate(240deg) translate(7.92px, 0px);
  176. transform: rotate(240deg) translate(7.92px, 0px);
  177. }
  178. .loading_leaf_9 {
  179. -webkit-animation: opacity-9 1.25s linear infinite;
  180. animation: opacity-9 1.25s linear infinite;
  181. }
  182. .loading_leaf_9:before {
  183. -webkit-transform: rotate(270deg) translate(7.92px, 0px);
  184. transform: rotate(270deg) translate(7.92px, 0px);
  185. }
  186. .loading_leaf_10 {
  187. -webkit-animation: opacity-10 1.25s linear infinite;
  188. animation: opacity-10 1.25s linear infinite;
  189. }
  190. .loading_leaf_10:before {
  191. -webkit-transform: rotate(300deg) translate(7.92px, 0px);
  192. transform: rotate(300deg) translate(7.92px, 0px);
  193. }
  194. .loading_leaf_11 {
  195. -webkit-animation: opacity-11 1.25s linear infinite;
  196. animation: opacity-11 1.25s linear infinite;
  197. }
  198. .loading_leaf_11:before {
  199. -webkit-transform: rotate(330deg) translate(7.92px, 0px);
  200. transform: rotate(330deg) translate(7.92px, 0px);
  201. }
  202. @-webkit-keyframes opacity-0 {
  203. 0% {
  204. opacity: 0.25;
  205. }
  206. 0.01% {
  207. opacity: 0.25;
  208. }
  209. 0.02% {
  210. opacity: 1;
  211. }
  212. 60.01% {
  213. opacity: 0.25;
  214. }
  215. 100% {
  216. opacity: 0.25;
  217. }
  218. }
  219. @keyframes opacity-0 {
  220. 0% {
  221. opacity: 0.25;
  222. }
  223. 0.01% {
  224. opacity: 0.25;
  225. }
  226. 0.02% {
  227. opacity: 1;
  228. }
  229. 60.01% {
  230. opacity: 0.25;
  231. }
  232. 100% {
  233. opacity: 0.25;
  234. }
  235. }
  236. @-webkit-keyframes opacity-1 {
  237. 0% {
  238. opacity: 0.25;
  239. }
  240. 8.34333% {
  241. opacity: 0.25;
  242. }
  243. 8.35333% {
  244. opacity: 1;
  245. }
  246. 68.3433% {
  247. opacity: 0.25;
  248. }
  249. 100% {
  250. opacity: 0.25;
  251. }
  252. }
  253. @keyframes opacity-1 {
  254. 0% {
  255. opacity: 0.25;
  256. }
  257. 8.34333% {
  258. opacity: 0.25;
  259. }
  260. 8.35333% {
  261. opacity: 1;
  262. }
  263. 68.3433% {
  264. opacity: 0.25;
  265. }
  266. 100% {
  267. opacity: 0.25;
  268. }
  269. }
  270. @-webkit-keyframes opacity-2 {
  271. 0% {
  272. opacity: 0.25;
  273. }
  274. 16.6767% {
  275. opacity: 0.25;
  276. }
  277. 16.6867% {
  278. opacity: 1;
  279. }
  280. 76.6767% {
  281. opacity: 0.25;
  282. }
  283. 100% {
  284. opacity: 0.25;
  285. }
  286. }
  287. @keyframes opacity-2 {
  288. 0% {
  289. opacity: 0.25;
  290. }
  291. 16.6767% {
  292. opacity: 0.25;
  293. }
  294. 16.6867% {
  295. opacity: 1;
  296. }
  297. 76.6767% {
  298. opacity: 0.25;
  299. }
  300. 100% {
  301. opacity: 0.25;
  302. }
  303. }
  304. @-webkit-keyframes opacity-3 {
  305. 0% {
  306. opacity: 0.25;
  307. }
  308. 25.01% {
  309. opacity: 0.25;
  310. }
  311. 25.02% {
  312. opacity: 1;
  313. }
  314. 85.01% {
  315. opacity: 0.25;
  316. }
  317. 100% {
  318. opacity: 0.25;
  319. }
  320. }
  321. @keyframes opacity-3 {
  322. 0% {
  323. opacity: 0.25;
  324. }
  325. 25.01% {
  326. opacity: 0.25;
  327. }
  328. 25.02% {
  329. opacity: 1;
  330. }
  331. 85.01% {
  332. opacity: 0.25;
  333. }
  334. 100% {
  335. opacity: 0.25;
  336. }
  337. }
  338. @-webkit-keyframes opacity-4 {
  339. 0% {
  340. opacity: 0.25;
  341. }
  342. 33.3433% {
  343. opacity: 0.25;
  344. }
  345. 33.3533% {
  346. opacity: 1;
  347. }
  348. 93.3433% {
  349. opacity: 0.25;
  350. }
  351. 100% {
  352. opacity: 0.25;
  353. }
  354. }
  355. @keyframes opacity-4 {
  356. 0% {
  357. opacity: 0.25;
  358. }
  359. 33.3433% {
  360. opacity: 0.25;
  361. }
  362. 33.3533% {
  363. opacity: 1;
  364. }
  365. 93.3433% {
  366. opacity: 0.25;
  367. }
  368. 100% {
  369. opacity: 0.25;
  370. }
  371. }
  372. @-webkit-keyframes opacity-5 {
  373. 0% {
  374. opacity: 0.270958333333333;
  375. }
  376. 41.6767% {
  377. opacity: 0.25;
  378. }
  379. 41.6867% {
  380. opacity: 1;
  381. }
  382. 1.67667% {
  383. opacity: 0.25;
  384. }
  385. 100% {
  386. opacity: 0.270958333333333;
  387. }
  388. }
  389. @keyframes opacity-5 {
  390. 0% {
  391. opacity: 0.270958333333333;
  392. }
  393. 41.6767% {
  394. opacity: 0.25;
  395. }
  396. 41.6867% {
  397. opacity: 1;
  398. }
  399. 1.67667% {
  400. opacity: 0.25;
  401. }
  402. 100% {
  403. opacity: 0.270958333333333;
  404. }
  405. }
  406. @-webkit-keyframes opacity-6 {
  407. 0% {
  408. opacity: 0.375125;
  409. }
  410. 50.01% {
  411. opacity: 0.25;
  412. }
  413. 50.02% {
  414. opacity: 1;
  415. }
  416. 10.01% {
  417. opacity: 0.25;
  418. }
  419. 100% {
  420. opacity: 0.375125;
  421. }
  422. }
  423. @keyframes opacity-6 {
  424. 0% {
  425. opacity: 0.375125;
  426. }
  427. 50.01% {
  428. opacity: 0.25;
  429. }
  430. 50.02% {
  431. opacity: 1;
  432. }
  433. 10.01% {
  434. opacity: 0.25;
  435. }
  436. 100% {
  437. opacity: 0.375125;
  438. }
  439. }
  440. @-webkit-keyframes opacity-7 {
  441. 0% {
  442. opacity: 0.479291666666667;
  443. }
  444. 58.3433% {
  445. opacity: 0.25;
  446. }
  447. 58.3533% {
  448. opacity: 1;
  449. }
  450. 18.3433% {
  451. opacity: 0.25;
  452. }
  453. 100% {
  454. opacity: 0.479291666666667;
  455. }
  456. }
  457. @keyframes opacity-7 {
  458. 0% {
  459. opacity: 0.479291666666667;
  460. }
  461. 58.3433% {
  462. opacity: 0.25;
  463. }
  464. 58.3533% {
  465. opacity: 1;
  466. }
  467. 18.3433% {
  468. opacity: 0.25;
  469. }
  470. 100% {
  471. opacity: 0.479291666666667;
  472. }
  473. }
  474. @-webkit-keyframes opacity-8 {
  475. 0% {
  476. opacity: 0.583458333333333;
  477. }
  478. 66.6767% {
  479. opacity: 0.25;
  480. }
  481. 66.6867% {
  482. opacity: 1;
  483. }
  484. 26.6767% {
  485. opacity: 0.25;
  486. }
  487. 100% {
  488. opacity: 0.583458333333333;
  489. }
  490. }
  491. @keyframes opacity-8 {
  492. 0% {
  493. opacity: 0.583458333333333;
  494. }
  495. 66.6767% {
  496. opacity: 0.25;
  497. }
  498. 66.6867% {
  499. opacity: 1;
  500. }
  501. 26.6767% {
  502. opacity: 0.25;
  503. }
  504. 100% {
  505. opacity: 0.583458333333333;
  506. }
  507. }
  508. @-webkit-keyframes opacity-9 {
  509. 0% {
  510. opacity: 0.687625;
  511. }
  512. 75.01% {
  513. opacity: 0.25;
  514. }
  515. 75.02% {
  516. opacity: 1;
  517. }
  518. 35.01% {
  519. opacity: 0.25;
  520. }
  521. 100% {
  522. opacity: 0.687625;
  523. }
  524. }
  525. @keyframes opacity-9 {
  526. 0% {
  527. opacity: 0.687625;
  528. }
  529. 75.01% {
  530. opacity: 0.25;
  531. }
  532. 75.02% {
  533. opacity: 1;
  534. }
  535. 35.01% {
  536. opacity: 0.25;
  537. }
  538. 100% {
  539. opacity: 0.687625;
  540. }
  541. }
  542. @-webkit-keyframes opacity-10 {
  543. 0% {
  544. opacity: 0.791791666666667;
  545. }
  546. 83.3433% {
  547. opacity: 0.25;
  548. }
  549. 83.3533% {
  550. opacity: 1;
  551. }
  552. 43.3433% {
  553. opacity: 0.25;
  554. }
  555. 100% {
  556. opacity: 0.791791666666667;
  557. }
  558. }
  559. @keyframes opacity-10 {
  560. 0% {
  561. opacity: 0.791791666666667;
  562. }
  563. 83.3433% {
  564. opacity: 0.25;
  565. }
  566. 83.3533% {
  567. opacity: 1;
  568. }
  569. 43.3433% {
  570. opacity: 0.25;
  571. }
  572. 100% {
  573. opacity: 0.791791666666667;
  574. }
  575. }
  576. @-webkit-keyframes opacity-11 {
  577. 0% {
  578. opacity: 0.895958333333333;
  579. }
  580. 91.6767% {
  581. opacity: 0.25;
  582. }
  583. 91.6867% {
  584. opacity: 1;
  585. }
  586. 51.6767% {
  587. opacity: 0.25;
  588. }
  589. 100% {
  590. opacity: 0.895958333333333;
  591. }
  592. }
  593. @keyframes opacity-11 {
  594. 0% {
  595. opacity: 0.895958333333333;
  596. }
  597. 91.6767% {
  598. opacity: 0.25;
  599. }
  600. 91.6867% {
  601. opacity: 1;
  602. }
  603. 51.6767% {
  604. opacity: 0.25;
  605. }
  606. 100% {
  607. opacity: 0.895958333333333;
  608. }
  609. }

参考

原文链接:http://www.cnblogs.com/moqiutao/p/14394973.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号