Js跑马灯效果 && 在Vue中使用
DEMO:
<!DOCTYPE html>
<html>
<head>
<title>滚动播报</title>
<meta charset="UTF-8">
<style>
.content {
height: 60px;
background-color: #2c2c34;
overflow: hidden;
}
.content ul {
white-space: nowrap;
}
.content ul li {
position: relative;
font-size: 14px;
vertical-align: middle;
line-height: 35px;
padding: 0 8px;
white-space: nowrap;
display: inline-block;
color: #fff
}
#scrollBox {
overflow: hidden;
}
#scrollBox .scrollWrap {
width: 500%
}
.scrollCont {
float: left;
}
</style>
</head>
<body>
<div class="content">
<ul>
<div id="scrollBox">
<div class="scrollWrap">
<div id="scrollContOne" class="scrollCont">
<li>我是第一条数据</li>
<li>我是第二条数据</li>
<li>我是第三条数据</li>
<li>我是第四条数据</li>
<li>我是第五条数据</li>
<li>我是第六条数据</li>
<li>我是第七条数据</li>
<li>我是第八条数据</li>
</div>
<div id="scrollContTwo" class="scrollCont"></div>
</div>
</div>
</ul>
</div>
<script>
let speed = 40
let scrollBox = document.getElementById("scrollBox");
let scrollContOne = document.getElementById("scrollContOne");
let scrollContTwo = document.getElementById("scrollContTwo");
scrollContTwo.innerHTML = scrollContOne.innerHTML;
scrollBox.scrollLeft = 0;
function scrollRadio() {
if (scrollBox.scrollLeft >= scrollContTwo.offsetWidth) {
scrollBox.scrollLeft -= scrollContOne.offsetWidth
} else {
scrollBox.scrollLeft += 2;
}
}
let MyScrollRadio = setInterval(scrollRadio, speed);
scrollBox.onmouseover = function() {
clearInterval(MyScrollRadio)
};
scrollBox.onmouseout = function() {
MyScrollRadio = setInterval(scrollRadio, speed)
};
</script>
</body>
</html>
在Vue中使用:
<template>
<div class="content">
<ul>
<div id="scrollBox">
<div class="scrollWrap">
<div id="scrollContOne" class="scrollCont">
<li v-for="item in items">
<a href="{{item}" target="_blank"></a>
</li>
</div>
<div id="scrollContTwo" class="scrollCont"></div>
</div>
</div>
</ul>
</div>
</template>
<style scoped>
.content {
height: 60px;
background-color: #2c2c34;
overflow: hidden;
}
.content ul {
white-space: nowrap;
}
.content ul li {
position: relative;
font-size: 14px;
vertical-align: middle;
line-height: 35px;
padding: 0 8px;
white-space: nowrap;
display: inline-block;
}
.content ul li a {
text-decoration: none;
color:#fff;
}
#scrollBox {
overflow: hidden;
margin-left: 36px;
}
#scrollBox .scrollWrap {
width: 500%
}
.scrollCont {
float: left;
}
</style>
<script>
export default {
data: () => ({
canScrollTimer: 0
}),
vuex: {
getters: {
scrollLists: state => state.scrollLists
}
},
watch:{
scrollLists:{
deep:true,
handler(v,ov){
if(v.length){
this.run();
}
}
}
},
methods: {
run() {
let speed = 40;
let scrollBox = document.getElementById("scrollBox");
let scrollContOne = document.getElementById("scrollContOne");
let scrollContTwo = document.getElementById("scrollContTwo");
scrollContTwo.innerHTML = scrollContOne.innerHTML;
scrollBox.scrollLeft = 0;
function scrollRadio() {
if (scrollBox.scrollLeft >= scrollContTwo.offsetWidth) {
scrollBox.scrollLeft -= scrollContOne.offsetWidth
} else {
scrollBox.scrollLeft += 2;
}
}
let MyScrollRadio = setInterval(scrollRadio, speed);
scrollBox.onmouseover = function() {
clearInterval(MyScrollRadio)
};
scrollBox.onmouseout = function() {
MyScrollRadio = setInterval(scrollRadio, speed)
};
}
},
ready() {
//接口调用
}
}
</script>
Js跑马灯效果 && 在Vue中使用的更多相关文章
- js跑马灯效果
function nextPage() { /* 克隆第一张图片并添加到box后 box前移一张图片的距离动画 动画回调里把box的 ...
- vue实现跑马灯效果
vue实现跑马灯效果为阿中哥哥应援 1.效果图 2.实现代码 <!DOCTYPE html> <html lang="en"> <head> & ...
- Vue学习笔记四:跑马灯效果
目录 跑马灯原理 HTML 箭头函数 计时器 跑马灯效果 跑马灯原理 先讲讲跑马灯的原理,就是一行字,会滚动,思路是这样的,使用substring方法,一个获取字符串的第一个字,一个获取1后面所有的字 ...
- 黑马vue---10-11、Vue实现跑马灯效果
黑马vue---10-11.Vue实现跑马灯效果 一.总结 一句话总结: 1. 给 [浪起来] 按钮,绑定一个点击事件 v-on @ 2. 在按钮的事件处理函数中,写相关的业务逻辑代码:拿到 ...
- VUE小案例--跑马灯效果
自学Vue课程中学到的一个小案例,跑马灯效果 <!DOCTYPE html> <html lang="zh-CN"> <head> <me ...
- JS实现跑马灯效果(向左,向上)
<html> <head> <title>JS实现跑马灯效果</title> <style> * { font-size:12px; fon ...
- 微信小程序跑马灯效果--基于CSS3 animation 及 基于JS
如果本文对你有用,请爱心点个赞,提高排名,帮助更多的人.谢谢大家!❤ 如果解决不了,可以在文末进群交流. 基于CSS3主要代码实现 效果图: 视图模板wxml中: <view class=&qu ...
- JS写一个列表跑马灯效果--基于touchslide.js
先放上效果图: 类似于这样的,在列表中循环添加背景样式的跑马灯效果. 准备引入JS插件: <script type="text/javascript" src="x ...
- vue学习第二天:Vue跑马灯效果制作
分析: 1. 给开始按钮绑定一个点击事件 2.在按钮的事件处理函数中,写相关的业务代码 3.拿到msg字符串 4.调用字符串的substring来进行字符串的截取操作 5.重新赋值利用vm实例的特性来 ...
随机推荐
- TP3.2.3 接入阿里sms 短信接口
阿里云短信接口 配置文件 config.php //阿里大鱼 'Ali_SMS' =>array( 'sms_temp' =>'短信模板', 'sms_sign' =>'签名', ' ...
- scala成长之路(4)compaion object——伴生对象的使用
虽然java一直声称自己是完全面向对象的语言,但一直以来都被很多人所质疑,其中java的静态成员函数就是主要的“罪魁祸首”.由于java中保留了静态方法的调用,导致其编程模式依然有过程式编程的可能,尤 ...
- python应用:异常处理
Python的错误异常在大部分IDE编辑器中则可以直接显示出来,便于开发人员的调试及修改工作,对初学者也比较友好. Python中包含错误和异常两种情况,错误主要是常见的语法错误SyntaxError ...
- mysql日志管理#二进制日志详解
查看MySQL二进制文件中的内容有两种方式 mysqlbinlog SHOW BINLOG EVENTS [IN 'log_name'] [FROM pos] [LIMIT [offset,] row ...
- 对bluebird的理解
前言 Promise:把原来的回调写法分离出来,在异步操作执行完后,用链式调用的方式执行回调函数. 在公众号的开发里面用的const Promise = require('bluebird');con ...
- UVA ~ 514 ~ Rails (栈)
参考:https://blog.csdn.net/ZscDst/article/details/80266639 #include <iostream> #include <cstd ...
- Create Fiori List App Report with ABAP CDS view – PART 1
From Create Fiori List App Report with ABAP CDS view – PART 1 In this blog, I am going to show How C ...
- Android StateListDrawable的坑
有问题的代码: StateListDrawable background = new StateListDrawable(); CircleDrawable pressedDrawable = new ...
- Java RMI 入门指南
开通博客也有好些天了,一直没有时间静下心来写博文,今天我就把两年前整理的一篇关于JAVA RMI入门级文章贴出来,供有这方面需要的同学们参考学习. RMI 相关知识 RMI全称是Remote Meth ...
- 超强排序JavaScript插件
Sortable:http://rubaxa.github.io/Sortable/