• js控制GIF图片播放暂停


    js控制GIF图片播放暂停

    1.效果如下:

    预览页:https://volodyan.github.io/vue3_poject_template_preview/#/

    2.使用libgif.js库

    3.源码如下:

      1 <template>
      2   <div class="SuperGifComponents">
      3     <div class="imgbox">
      4       <img
      5         id="example1"
      6         :src="imgUrl"
      7         :rel:animated_src="imgUrlGIF"
      8         rel:auto_play="0"
      9         width="467"
     10         height="375"
     11       />
     12     </div>
     13 
     14     <div class="Buttonbox">
     15       <div
     16         v-for="(item, index) in tabrooms"
     17         :key="index"
     18         class="itembox"
     19         @click="tabClickfun(item, index)"
     20       >
     21         {{ item }}
     22       </div>
     23     </div>
     24   </div>
     25 </template>
     26 <script>
     27 import SuperGif from "./libgif/libgif.js";
     28 export default {
     29   name: "SuperGifComponents",
     30   data() {
     31     return {
     32       tabrooms: ["Pause", "Play", "Restart", "Step forward", "Step back"],
     33       imgUrl: require("@/assets/img/fish.png"),
     34       imgUrlGIF: require("@/assets/img/fish.gif"),
     35       sup1: null,
     36     };
     37   },
     38   async mounted() {
     39     try {
     40       this.InitSuperGif();
     41     } catch (e) {
     42       console.error("程序错误", e);
     43     }
     44   },
     45   methods: {
     46     InitSuperGif() {
     47       console.log("SuperGif", SuperGif);
     48       // 通过异步函数,获取gif文件
     49       var sup1 = new SuperGif({
     50         gif: document.getElementById("example1"),
     51         progressbar_foreground_color:"#9254de",
     52         progressbar_background_color :"#ebeef5",
     53         progressbar_height:10
     54       });
     55 
     56       sup1.load();
     57       this.sup1 = sup1;
     58     },
     59     tabClickfun(item, index) {
     60       //["Pause", "Play", "Restart", "Step forward", "Step back"]
     61       if (item === "Pause") {
     62         this.sup1.pause();
     63       } else if (item === "Play") {
     64         this.sup1.play();
     65       } else if (item === "Restart") {
     66         this.sup1.move_to(0);
     67       } else if (item === "Step forward") {
     68         this.sup1.move_relative(1);
     69       } else if (item === "Step back") {
     70         this.sup1.move_relative(-1);
     71       }
     72     },
     73   },
     74 };
     75 </script>
     76  
     77 <style lang="scss" scoped>
     78 .SuperGifComponents {
     79    60%;
     80   .imgbox {
     81      60%;
     82   }
     83   .Buttonbox {
     84     display: flex;
     85     flex-flow: row nowrap;
     86     margin: 30px;
     87     .itembox {
     88       //  86px;
     89       padding: 0 15px;
     90       height: 32px;
     91       line-height: 32px;
     92       text-align: center;
     93       white-space: nowrap;
     94       cursor: pointer;
     95       background: coral;
     96       margin-right: 10px;
     97       color: #fff;
     98       &:hover {
     99         background: rgb(219, 148, 122);
    100       }
    101     }
    102   }
    103 }
    104 </style>
    View Code
     
  • 相关阅读:
    react实现登陆页面
    “css中设置边框不显示,border:none; 和border:0; 都没用”的解决方案
    JQuery AJAX的post()方法和get()方法的区别
    JQuery事件之文档/窗口事件
    JQuery事件之表单事件
    【K8S初识】-什么是Kubernetes
    Yaml语法理解
    Json语法理解
    Maven学习-Maven工程中默认的环境变量
    Java语言(7)-Java中的注解
  • 原文地址:https://www.cnblogs.com/volodya/p/14207800.html
Copyright © 2020-2023  润新知