js控制GIF图片播放暂停
1.下载libgif,在项目中新建libgif.js文件
2.在组件中引入libgif.js文件,并使用
<template>
<div class="gifComponents">
<div class="imgbox">
<img
id="example1"
:src="imgUrl"
:rel:animated_src="imgUrlGIF"
rel:auto_play="0"
width="467"
height="375"
/>
</div>
<div class="Buttonbox">
<div
v-for="(item, index) in tabrooms"
:key="index"
class="itembox"
@click="tabClickfun(item, index)"
>
{{ item }}
</div>
</div>
</div>
</template>
<script>
import SuperGif from "./libgif.js";
export default {
name: "gifComponents",
data() {
return {
tabrooms: ["Pause", "Play", "Restart", "Step forward", "Step back"],
imgUrl: require("@/assets/img/fish.png"),
imgUrlGIF: require("@/assets/img/fish.gif"),
sup1: null,
};
},
async mounted() {
try {
this.InitSuperGif();
} catch (e) {
console.error("程序错误", e);
}
},
methods: {
InitSuperGif() {
console.log("SuperGif", SuperGif);
// 通过异步函数,获取gif文件
var sup1 = new SuperGif({
gif: document.getElementById("example1"),
progressbar_foreground_color: "#9254de",
progressbar_background_color: "#ebeef5",
progressbar_height: 10,
});
sup1.load();
this.sup1 = sup1;
},
tabClickfun(item, index) {
//["Pause", "Play", "Restart", "Step forward", "Step back"]
if (item === "Pause") {
this.sup1.pause();
} else if (item === "Play") {
this.sup1.play();
} else if (item === "Restart") {
this.sup1.move_to(0);
} else if (item === "Step forward") {
this.sup1.move_relative(1);
} else if (item === "Step back") {
this.sup1.move_relative(-1);
}
},
},
};
</script>
<style lang="scss" scoped>
.gifComponents {
width: 50%;
margin-top: 30px;
.imgbox {
width: 100%;
}
.Buttonbox {
display: flex;
flex-flow: row nowrap;
justify-content: flex-start;
margin-left: 90px;
margin-top: 30px;
.itembox {
width: 96px;
padding: 0 15px;
height: 32px;
line-height: 32px;
text-align: center;
white-space: nowrap;
cursor: pointer;
background: coral;
margin-right: 10px;
color: #fff;
&:hover {
background: rgb(219, 148, 122);
}
}
}
}
</style>
3.控制gif图片的组件在其他组件中使用
<template>
<div class="home">
<gifComponents />
</div>
</template>
<script>
import gifComponents from "./gifComponents/index.vue";
export default {
name: "Home",
components: {
gifComponents,
},
};
</script>
<style lang="scss" scoped>
.home {
display: flex;
flex-flow: row nowrap;
justify-content: center;
//align-items: center;
width: 100%;
height: 100%;
background: $exportedValue;
}
</style>

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· .NET Core 中如何实现缓存的预热?
· 三行代码完成国际化适配,妙~啊~
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
2018-12-29 Vue2、websocket 与node.js接口 本地测试