一:文字跑马灯wxml <view>1 显示完后再显示</view>
<view class="example">
<view class="marquee_box">
<view class="marquee_text" style="{{orientation}}:{{marqueeDistance}}px;font-size: {{size}}px;">
{{text}}
</view>
</view>
</view>
<view>2 出现白边后即显示</view>
<view class="example">
<view class="marquee_box">
<view class="marquee_text" style="{{orientation}}:{{marqueeDistance2}}px;font-size: {{size}}px;">
<text>{{text}}</text>
<text wx:if="{{marquee2copy_status}}" style="margin-left:{{marquee2_margin}}px;">{{text}}</text>
</view>
</view>
</view>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
wxss .example {
display: block;
width: 100%;
height: 100rpx;
}
.marquee_box {
width: 100%;
position: relative;
}
.marquee_text {
white-space: nowrap;
position: absolute;
top: 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
js
Page({
data: {
text: '这是一条会滚动的文字滚来滚去的文字跑马灯,哈哈哈哈哈哈哈哈',
marqueePace: 1,
marqueeDistance: 0,
marqueeDistance2: 0,
marquee2copy_status: false,
marquee2_margin: 60,
size: 14,
orientation: 'left',
interval: 20
},
onShow: function () {
var vm = this;
var length = vm.data.text.length * vm.data.size;
var windowWidth = wx.getSystemInfoSync().windowWidth;
vm.setData({
length: length,
windowWidth: windowWidth,
marquee2_margin: length < windowWidth ? windowWidth - length : vm.data.marquee2_margin
});
vm.run1();
vm.run2();
},
run1: function () {
var vm = this;
var interval = setInterval(function () {
if (-vm.data.marqueeDistance < vm.data.length) {
vm.setData({
marqueeDistance: vm.data.marqueeDistance - vm.data.marqueePace,
});
} else {
clearInterval(interval);
vm.setData({
marqueeDistance: vm.data.windowWidth
});
vm.run1();
}
}, vm.data.interval);
},
run2: function () {
var vm = this;
var interval = setInterval(function () {
if (-vm.data.marqueeDistance2 < vm.data.length) {
vm.setData({
marqueeDistance2: vm.data.marqueeDistance2 - vm.data.marqueePace,
marquee2copy_status: vm.data.length + vm.data.marqueeDistance2 <= vm.data.windowWidth + vm.data.marquee2_margin,
});
} else {
if (-vm.data.marqueeDistance2 >= vm.data.marquee2_margin) {
vm.setData({
marqueeDistance2: vm.data.marquee2_margin
});
clearInterval(interval);
vm.run2();
} else {
clearInterval(interval);
vm.setData({
marqueeDistance2: -vm.data.windowWidth
});
vm.run2();
}
}
}, vm.data.interval);
}
})
二:仿table效果 wxml代码: <view class="container">
<view class="table">
<view class="tr">
<view class="th">标题1</view>
<view class="th">标题2</view>
<view class="th">标题3</view>
<view class="th">标题4</view>
<view class="th">标题5</view>
</view>
<view class="tr" wx:for="{{5}}">
<view class="td">{{内容}}</view>
<view class="td">{{内容}}</view>
<view class="td">{{内容}}</view>
<view class="td">{{内容}}</view>
<view class="td">{{内容}}</view>
</view>
</view>
</view>
wxss代码:
/* pages/table/table.wxss */
page {
font-size: 14px;
color: #333
}
.table {
border:1px solid #dadada;
border-right: 0;
border-bottom: 0;
width: 98%;
}
.tr {
width: 100%;
display: flex;
justify-content: space-between;
}
.th,.td {
padding: 10px;
border-bottom: 1px solid #dadada;
border-right: 1px solid #dadada;
text-align: center;
width:100%
}
.th {
font-weight: 400;
background-color: #dadada
}
|