首页 >> js开发 >> js微信小程序实现简单文字跑马灯js大全
js微信小程序实现简单文字跑马灯js大全
发布时间: 2021年1月13日 | 浏览:
| 分类:js开发
本文实例为大家分享了微信小程序实现文字跑马灯 的具体代码,供大家参考,具体内容如下效果如图WXML
{{text}}
{{text}}
{{text}}
{{text}}
WXSS
.container {display: flex;flex-direction: column;justify-content: space-between;box-sizing: border-box;}
.scrolltxt{padding:0 20rpx;background:#f8f8f8;}
.marquee_box {position:relative;color:#333;height:90rpx;display:block;overflow:hidden;}
.marquee_text {white-space: nowrap;position:absolute;top:0;font-size:14px;height:90rpx;line-height:90rpx;}
.container {display: flex;flex-direction: column;justify-content: space-between;box-sizing: border-box;}
.scrolltxt{padding:0 20rpx;background:#f8f8f8;}
.marquee_box {position:relative;color:#333;height:90rpx;display:block;overflow:hidden;}
.marquee_text {white-space: nowrap;position:absolute;top:0;font-size:14px;height:90rpx;line-height:90rpx;}JS
data: {
//滚动字幕
text: "温馨提示:为了保证其他购买者的利益,每个 账号针对同一商品只允许退款一次,请您谨慎操作。",
marqueePace: 1,//滚动速度
marqueeDistance: 0,//初始滚动距离
marquee_margin: 30,//间距
size: 14,//字号
time: '',// 定时器
},
onHide: function () {
//清空滚动字幕定时器,避免锁屏或页面隐藏后移动速度越来越快
clearInterval(this.data.time);
},
onShow: function (e) {
var that = this;
var length = that.data.text.length * that.data.size;//文字长度
var windowWidth = wx.getSystemInfoSync().windowWidth;// 屏幕宽度
//console.log(length,windowWidth);
that.setData({
length: length,
windowWidth: windowWidth
});
that.scrolltxt();// 第一个字消失后立即从右边出现
},
/**
* 滚动字幕
*/
scrolltxt: function () {
var that = this;
var length = that.data.length;//滚动文字的宽度
var windowWidth = that.data.windowWidth;//屏幕宽度
var time = this.data.time
if (length > windowWidth) {
time = setInterval(function () {
var maxscrollwidth = length + that.data.marquee_margin;//滚动的最大宽度,文字宽度+间距,如果需要一行文字滚完后再显示第二行可以修改marquee_margin值等于windowWidth即可
var crentleft = that.data.marqueeDistance;
if (crentleft < maxscrollwidth) {//判断是否滚动到最大宽度
that.setData({
marqueeDistance: crentleft + that.data.marqueePace
})
}
else {
that.setData({
marqueeDistance: 0 // 直接重新滚动
});
clearInterval(time);
that.scrolltxt();
}
}, 20);
}
else {
that.setData({ marquee_margin: "1000" });//只显示一条不滚动右边间距加大,防止重复显示
}
that.setData({
time:time
})
},
data: {
//滚动字幕
text: "温馨提示:为了保证其他购买者的利益,每个 账号针对同一商品只允许退款一次,请您谨慎操作。",
marqueePace: 1,//滚动速度
marqueeDistance: 0,//初始滚动距离
marquee_margin: 30,//间距
size: 14,//字号
time: '',// 定时器
},
onHide: function () {
//清空滚动字幕定时器,避免锁屏或页面隐藏后移动速度越来越快
clearInterval(this.data.time);
},
onShow: function (e) {
var that = this;
var length = that.data.text.length * that.data.size;//文字长度
var windowWidth = wx.getSystemInfoSync().windowWidth;// 屏幕宽度
//console.log(length,windowWidth);
that.setData({
length: length,
windowWidth: windowWidth
});
that.scrolltxt();// 第一个字消失后立即从右边出现
},
/**
* 滚动字幕
*/
scrolltxt: function () {
var that = this;
var length = that.data.length;//滚动文字的宽度
var windowWidth = that.data.windowWidth;//屏幕宽度
var time = this.data.time
if (length > windowWidth) {
time = setInterval(function () {
var maxscrollwidth = length + that.data.marquee_margin;//滚动的最大宽度,文字宽度+间距,如果需要一行文字滚完后再显示第二行可以修改marquee_margin值等于windowWidth即可
var crentleft = that.data.marqueeDistance;
if (crentleft < maxscrollwidth) {//判断是否滚动到最大宽度
that.setData({
marqueeDistance: crentleft + that.data.marqueePace
})
}
else {
that.setData({
marqueeDistance: 0 // 直接重新滚动
});
clearInterval(time);
that.scrolltxt();
}
}, 20);
}
else {
that.setData({ marquee_margin: "1000" });//只显示一条不滚动右边间距加大,防止重复显示
}
that.setData({
time:time
})
},为大家推荐现在关注度比较高的微信小程序教程一篇:《微信小程序开发教程》小编为大家精心整理的,希望喜欢。《微信小程序开发教程》以上就是本文的全部内容,希望对大家的学习有所帮助。
.container {display: flex;flex-direction: column;justify-content: space-between;box-sizing: border-box;}
.scrolltxt{padding:0 20rpx;background:#f8f8f8;}
.marquee_box {position:relative;color:#333;height:90rpx;display:block;overflow:hidden;}
.marquee_text {white-space: nowrap;position:absolute;top:0;font-size:14px;height:90rpx;line-height:90rpx;}
.container {display: flex;flex-direction: column;justify-content: space-between;box-sizing: border-box;}
.scrolltxt{padding:0 20rpx;background:#f8f8f8;}
.marquee_box {position:relative;color:#333;height:90rpx;display:block;overflow:hidden;}
.marquee_text {white-space: nowrap;position:absolute;top:0;font-size:14px;height:90rpx;line-height:90rpx;}JS
data: {
//滚动字幕
text: "温馨提示:为了保证其他购买者的利益,每个 账号针对同一商品只允许退款一次,请您谨慎操作。",
marqueePace: 1,//滚动速度
marqueeDistance: 0,//初始滚动距离
marquee_margin: 30,//间距
size: 14,//字号
time: '',// 定时器
},
onHide: function () {
//清空滚动字幕定时器,避免锁屏或页面隐藏后移动速度越来越快
clearInterval(this.data.time);
},
onShow: function (e) {
var that = this;
var length = that.data.text.length * that.data.size;//文字长度
var windowWidth = wx.getSystemInfoSync().windowWidth;// 屏幕宽度
//console.log(length,windowWidth);
that.setData({
length: length,
windowWidth: windowWidth
});
that.scrolltxt();// 第一个字消失后立即从右边出现
},
/**
* 滚动字幕
*/
scrolltxt: function () {
var that = this;
var length = that.data.length;//滚动文字的宽度
var windowWidth = that.data.windowWidth;//屏幕宽度
var time = this.data.time
if (length > windowWidth) {
time = setInterval(function () {
var maxscrollwidth = length + that.data.marquee_margin;//滚动的最大宽度,文字宽度+间距,如果需要一行文字滚完后再显示第二行可以修改marquee_margin值等于windowWidth即可
var crentleft = that.data.marqueeDistance;
if (crentleft < maxscrollwidth) {//判断是否滚动到最大宽度
that.setData({
marqueeDistance: crentleft + that.data.marqueePace
})
}
else {
that.setData({
marqueeDistance: 0 // 直接重新滚动
});
clearInterval(time);
that.scrolltxt();
}
}, 20);
}
else {
that.setData({ marquee_margin: "1000" });//只显示一条不滚动右边间距加大,防止重复显示
}
that.setData({
time:time
})
},
data: {
//滚动字幕
text: "温馨提示:为了保证其他购买者的利益,每个 账号针对同一商品只允许退款一次,请您谨慎操作。",
marqueePace: 1,//滚动速度
marqueeDistance: 0,//初始滚动距离
marquee_margin: 30,//间距
size: 14,//字号
time: '',// 定时器
},
onHide: function () {
//清空滚动字幕定时器,避免锁屏或页面隐藏后移动速度越来越快
clearInterval(this.data.time);
},
onShow: function (e) {
var that = this;
var length = that.data.text.length * that.data.size;//文字长度
var windowWidth = wx.getSystemInfoSync().windowWidth;// 屏幕宽度
//console.log(length,windowWidth);
that.setData({
length: length,
windowWidth: windowWidth
});
that.scrolltxt();// 第一个字消失后立即从右边出现
},
/**
* 滚动字幕
*/
scrolltxt: function () {
var that = this;
var length = that.data.length;//滚动文字的宽度
var windowWidth = that.data.windowWidth;//屏幕宽度
var time = this.data.time
if (length > windowWidth) {
time = setInterval(function () {
var maxscrollwidth = length + that.data.marquee_margin;//滚动的最大宽度,文字宽度+间距,如果需要一行文字滚完后再显示第二行可以修改marquee_margin值等于windowWidth即可
var crentleft = that.data.marqueeDistance;
if (crentleft < maxscrollwidth) {//判断是否滚动到最大宽度
that.setData({
marqueeDistance: crentleft + that.data.marqueePace
})
}
else {
that.setData({
marqueeDistance: 0 // 直接重新滚动
});
clearInterval(time);
that.scrolltxt();
}
}, 20);
}
else {
that.setData({ marquee_margin: "1000" });//只显示一条不滚动右边间距加大,防止重复显示
}
that.setData({
time:time
})
},为大家推荐现在关注度比较高的微信小程序教程一篇:《微信小程序开发教程》小编为大家精心整理的,希望喜欢。《微信小程序开发教程》以上就是本文的全部内容,希望对大家的学习有所帮助。
相关文章:
- jsvue+axios全局添加请求头和参数操作js大全
- js在vue中使用防抖函数组件操作js大全
- jsVue中的this.$options.data()和this.$data用法说明js大全
- jsElement Breadcrumb 面包屑的使用方法js大全
- js解决vue动态路由异步加载import组件,加载不到module的问题js大全
- jsAngular利用HTTP POST下载流文件的步骤记录js大全
- js解决vuex数据页面刷新后初始化操作js大全
- jsvue 页面回退mounted函数不执行的解决方案js大全
- jsvue项目使用$router.go(-1)返回时刷新原来的界面操作js大全
- jsElement Input输入框的使用方法js大全