This time I will bring you vue to implement image marquee scrolling. What are the precautions for vue to implement image marquee scrolling. The following is a practical case, let's take a look.
Father:
<template> <p> <er-carousel-index> <template>-----使用子组件传过来的值,封装slot <p> </p> <p> <a> <img class="minMax lazy" src="/static/imghwm/default1.png" data-src="props.item.img" alt="Vue implements marquee scrolling of pictures" > </a> </p> </template></er-carousel-index></p> <p> </p> <p> <a>{{props.item.title}}</a> </p> </template> <script> import ErCarouselIndex from './components/carouselIndex/src/carouselIndex.vue' export default { name: 'app', data() { } }, components: { ErCarouselIndex//一定要进行组件声明,不然不能引用子组件 } } </script>
Subcomponent:
<template> <p> <span></span> <span></span> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> <slot></slot> </p> </template> <script> export default { name: "ErCarouselIndex", data(){ return { imgList: [],//请求接口数据 imgLisShow: [],//图片滚动数据,包括左中右三种 timer: null,//自动循环滚动时的间隔时间 timeout:null,//长按时的图片滚动间隔时间 index:0,//图片索引 translateXnum:0,//图片滚动时的偏移量 translateX:"",//生成图片偏移时的表达式 imgWidth:"",//图片所占宽度 timeDown:"",//鼠标刚按下时的时间 timeup:"",//鼠标松开时的时间 clickSpace:"",//鼠标按下松开的时间间隙 transFlag:true,//是否匀速滚动, transitionTime:"", indexCircle:0//小圆圈滚动索引 } }, props:{ duration:0,//图片延时滚动 typeNumber:0, //每次滚动几张 timeSpace:0, //图片滚动时间间隔 url:String,//请求接口地址 pageNumber:0,//当前页面显示几张图片 isOrNotButton:true,//是否显示左右按钮 isOrNotCircle:true,//是否显示小圆圈 imgHeight:""//图片滚动显示高度 }, watch:{ index:{ handler(){ var _this=this; if(Math.abs(this.index)==this.imgList.length){ this.indexCircle=0; setTimeout(function(){ _this.reset(); },_this.duration*1000*0.98); }else{ this.indexCircle=this.index; } this.calcXnum(); } }, translateXnum:{ handler(){ this.translateX="translateX("+this.translateXnum+"%)"; } } }, methods:{ //页面初始化复赋值 imgView:function() { var _this = this; _this.$http.get(_this.url).then(function (res) { _this.imgList = res.data.imgList; for(var i=0;i<3;i++){ _this.imgList.forEach(function (item, index) { _this.imgLisShow.push(item); }); } _this.reset(); _this.slideAuto(); _this.imgWidth=(100/_this.pageNumber)-1; _this.transitionTime="all "+_this.duration*0.98+"s linear"; console.log(_this.transitionTime); }); }, //图片滚动方法(长按) imgMove:function(direct){ var _this = this; _this.timeDown=new Date();//记录按下的时间 _this.timeout = setInterval(function() { if(direct=="mouseLeft") { _this.leftMove(); }else{ _this.rightMove(); } },300); }, //鼠标送开时执行的方法 cancelMove:function(direct){ var _this = this; _this.clearAuto(); this.timeup=new Date();//记录松开的时间 this.clickSpace=this.timeup.getTime() - this.timeDown.getTime(); //时间间隔小于500毫秒为点击,反之为长按 if(this.clickSpace<500){ for(var i=0;i<_this.typeNumber;i++){ if(direct=="left"){ _this.leftMove(); }else{ _this.rightMove(); } } } if (this.timeout) { clearInterval(this.timeout); this.timeout = null; } }, //向左移动 leftMove:function(){ this.index--; this.transFlag=true; }, //向右移动 rightMove:function(){ this.transFlag=true; this.index++; }, slideAuto:function () { var _this = this; _this.timer = setTimeout(function () { if(Math.abs(_this.index)!==_this.imgList.length){ _this.rightMove(); _this.slideAuto(); } }, _this.timeSpace * 1000); }, clearAuto:function () { console.log("停止"); if (this.timer) { clearInterval(this.timer); this.timer = null; } }, //重置 reset:function(){ this.index=0; this.transFlag=false; this.calcXnum(); }, calcXnum:function(){ var _this=this; this.translateXnum=-(this.index+this.imgList.length)*(100/this.pageNumber); }, //点击圆圈跳转图片 circleClick:function(dex){ this.index=dex; this.clearAuto(); } }, mounted() { this.$nextTick(function () { this.imgView(); }); } } </script>
This component is relatively complete in function. Users can pass parameters to control how many pictures need to be displayed on the current page, the image scrolling time interval, whether to display left and right click buttons, etc. For detailed parameters, you can view props, which are all commented with .
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
What are the tips for Vue component development
axios sends a post request and springMVC cannot accept parameters. How to deal with it
How to implement vue axios interrupt request when switching pages
The above is the detailed content of Vue implements marquee scrolling of pictures. For more information, please follow other related articles on the PHP Chinese website!

网上下载的 pdf 学习资料有一些会带有水印,非常影响阅读。比如下面的图片就是在 pdf 文件上截取出来的,今天我们就来用Python解决这个问题。安装模块PIL:Python Imaging Library 是 python 上非常强大的图像处理标准库,但是只能支持 python 2.7,于是就有志愿者在 PIL 的基础上创建了支持 python 3的 pillow,并加入了一些新的特性。pip install pillow pymupdf 可以用 python 访问扩展名为*.pdf、

JavaScript如何实现滚动到指定元素位置的功能?在网页中,当我们需要将用户的视线聚焦到某个特定的元素位置时,我们可以使用JavaScript来实现滚动到指定元素位置的功能。本文将介绍如何通过JavaScript实现这一功能,并提供相应的代码示例。首先,我们需要获取目标元素的位置信息。可以使用Element.getBoundingClient

如何监听一个iframe的滚动,需要具体代码示例当我们在网页中使用iframe标签嵌入其他网页时,有时候需要对iframe中的内容进行一些特定的操作。其中一个常见的需求是监听iframe的滚动事件,以便在滚动发生时执行相应的代码。以下将介绍如何使用JavaScript来监听一个iframe的滚动,并提供具体的代码示例供参考。获取iframe元素首先,我们需要

HTML、CSS和jQuery:制作一个自动滚动的公告栏在现代网页设计中,公告栏常常被用来重要的信息传达和引起用户注意。一个自动滚动的公告栏在网页上受到了广泛的应用,它能够让公告内容以动画形式在页面中滚动显示,提高信息的展示效果和用户体验。本文将介绍如何使用HTML、CSS和jQuery来制作一个自动滚动的公告栏,并提供具体的代码示例。首先,我们需要一个HT

此前,PS的重建图像功能就让人无比振奋,让无数人惊呼今天,StabilityAI又放大招了。它联合Clipdrop推出了UncropClipdrop——一个终极图像比例编辑器。从Uncrop这个名字上,我们就能看出它的用途。它是一个AI生成的「外画」工具,通过创建扩展背景,这个工具可以补充任何现有照片或图像,来更改任何图像的比例。敲黑板:通过Clipdrop网站,就可以免费试用这个工具了,无需登录!比例任意调,满意为止Uncrop基于StabilityAI的文本到图像模型StableDiffus

在网页开发中,图片预载是一种常见的技术,可以提升用户的体验感。当用户浏览网页时,图片可以提前下载并加载,减少图片加载时的等待时间。在Vue框架中,我们可以通过一些简单的方法来实现图片预载。本文将介绍Vue中的图片预载技术,包括预载的原理、实现的方法和使用注意事项。一、预载的原理首先,我们来了解一下图片预载的原理。传统的图片加载方式是等到图片全部下载完成才显示

vue报错找不到图片的解决办法:1、修改配置文件,将绝对路径改为相对路径;2、将图片作为模块加载进去,并将图片放到static目录下;3、将imageUrls引入响应的vue文件中,解析引用即可。

JavaScript如何实现滚动到页面底部自动加载的无限滚动效果?无限滚动效果是现代网页开发中常见的功能之一,它可以在滚动到页面底部时自动加载更多内容,使得用户可以无需手动点击按钮或链接就能够获取更多的数据或资源。在本文中,我们将探讨如何使用JavaScript来实现这一功能,并提供具体的代码示例。实现滚动到页面底部自动加载的无限滚动效果,主要分为以下


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 Linux new version
SublimeText3 Linux latest version

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!
