Commit c56ab130 authored by sixgod1234's avatar sixgod1234

切换骰子图片

parent 6dc6df3c
# ChangeImage # ChangeImage
长按骰子图片实现图片切换 长按骰子图片实现图片切换
\ No newline at end of file 开发工具:微信开发者工具。win10系统
\ No newline at end of file
// app.js
App({
onLaunch() {
// 展示本地存储能力
const logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
// 登录
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
}
})
},
globalData: {
userInfo: null
}
})
{
"pages":[
"pages/index/index",
"pages/logs/logs"
],
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "Weixin",
"navigationBarTextStyle":"black",
"initialRenderingCache": "static"
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}
/**app.wxss**/
.container {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
padding: 200rpx 0;
box-sizing: border-box;
}
// index.js
// 获取应用实例
const app = getApp()
Page({
data: {
timeId:'',
timeId2:'',
// 展示哪张图片的标识
isShowArr:[1,2,3,4],
isShow:0,
// 间隔时间,对应长按1s,2s,5s,7s,10s
timeIds:[1,3,2,3],
i: 0,
j: 0,
timem: 0
},
changeTime(){
// 浅拷贝 复制了引用 可以同时改变数组
var _this = this.data;
// 第一遍循环完之后就循环完了之后重置为第1张,且第一张的图片暂停时间为两秒
if(_this.i===4){
_this.timeIds[0] = 2;
_this.j=0;
_this.i=0;
}
this.setData({
isShow:_this.isShowArr[_this.j]
})
_this.i++;
_this.j++;
this.data.timeId = setTimeout(this.changeTime,_this.timeIds[_this.i-1]*1000)
},
//touch start
handleTouchStart: function(e) {
// setInterval记时间不准确
this.data.timeId2 = setTimeout(this.changeTime,1000)
},
//touch end
handleTouchEnd: function(e) {
clearTimeout(this.data.timeId);
clearTimeout(this.data.timeId2);
var _this = this.data;
_this.j=0;
_this.i=0;
_this.timeIds[0] = 1;
this.setData({
isShow:0
})
},
})
\ No newline at end of file
{
"usingComponents": {},
"initialRenderingCache": "static"
}
\ No newline at end of file
<view class="container">
<!-- 初始图 -->
<view class="imgsBG {{isDoudong?'doudong':''}}" style="background: url(' https://img.hxyxyz.top/images/2021/03/23/2.png') 49% 90% no-repeat;background-size:44% 44.5%;display:{{isShow === 0 ? 'block' : 'none'}}">
</view>
<!-- 2-4 -->
<view class="imgsBG" style="background: url('https://img.hxyxyz.top/images/2021/03/23/2-4-x.png') 49.8% 89.2% no-repeat;background-size:43.5% 42%;display:{{isShow === 1 ? 'block' : 'none'}}">
</view>
<!-- 5-7 -->
<view class="imgsBG" style="background: url('https://img.hxyxyz.top/images/2021/03/23/5-7-x.png') 37.8% 89% no-repeat;background-size:54.5% 41.8%;display:{{isShow === 2 ? 'block' : 'none'}}">
</view>
<!-- 7-9 -->
<view class="imgsBG" style="background: url('https://img.hxyxyz.top/images/2021/03/23/7-9-x.png') 37.8% 89% no-repeat;background-size:54.4% 42%;display:{{isShow === 3 ? 'block' : 'none'}}">
</view>
<!-- 9-12 -->
<view class="imgsBG" style="background: url('https://img.hxyxyz.top/images/2021/03/23/9-12-x.png') 30% 89% no-repeat;background-size:71.2% 43.5%;display:{{isShow === 4 ? 'block' : 'none'}}">
</view>
<!-- 骰子 -->
<view class="imgs" data-isShow="{{isShow}}" bindtouchstart="handleTouchStart"
bindtouchend="handleTouchEnd"
style="background: url('https://img.hxyxyz.top/images/2021/03/23/21942299424de2b2e6562e19a0fa4eb8.png') 53% 17% no-repeat;background-size:45% 45%">
</view>
</view>
\ No newline at end of file
page{ background:#99D365; }
.container {
top:0;
left:0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
padding: 0;
}
.imgsBG{
position: absolute;
bottom: 11.5%;
width: 856rpx;
height: 845rpx;
z-index: 0;
/* display: flex;
flex-direction: column;
align-items: center; */
}
.imgs{
position: absolute;
bottom: 11.5%;
width: 386rpx;
height: 339rpx;
z-index: 100;
}
\ No newline at end of file
// logs.js
const util = require('../../utils/util.js')
Page({
data: {
logs: []
},
onLoad() {
this.setData({
logs: (wx.getStorageSync('logs') || []).map(log => {
return util.formatTime(new Date(log))
})
})
}
})
{
"navigationBarTitleText": "查看启动日志",
"usingComponents": {}
}
\ No newline at end of file
<!--logs.wxml-->
<view class="container log-list">
<block wx:for="{{logs}}" wx:for-item="log">
<text class="log-item">{{index + 1}}. {{log}}</text>
</block>
</view>
.log-list {
display: flex;
flex-direction: column;
padding: 40rpx;
}
.log-item {
margin: 10rpx;
}
{
"description": "项目配置文件",
"packOptions": {
"ignore": []
},
"setting": {
"urlCheck": true,
"es6": true,
"enhance": false,
"postcss": true,
"preloadBackgroundData": false,
"minified": true,
"newFeature": false,
"coverView": true,
"nodeModules": false,
"autoAudits": false,
"showShadowRootInWxmlPanel": true,
"scopeDataCheck": false,
"uglifyFileName": false,
"checkInvalidKey": true,
"checkSiteMap": true,
"uploadWithSourceMap": true,
"compileHotReLoad": false,
"useMultiFrameRuntime": false,
"useApiHook": true,
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
},
"enableEngineNative": false,
"bundle": false,
"useIsolateContext": true,
"useCompilerModule": true,
"userConfirmedUseCompilerModuleSwitch": false,
"userConfirmedBundleSwitch": false,
"packNpmManually": false,
"packNpmRelationList": [],
"minifyWXSS": true
},
"compileType": "miniprogram",
"libVersion": "2.15.0",
"appid": "wx6f93446944c8b4c4",
"projectname": "changeImages",
"debugOptions": {
"hidedInDevtools": []
},
"scripts": {},
"isGameTourist": false,
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},
"condition": {
"search": {
"list": []
},
"conversation": {
"list": []
},
"game": {
"list": []
},
"plugin": {
"list": []
},
"gamePlugin": {
"list": []
},
"miniprogram": {
"list": []
}
}
}
\ No newline at end of file
{
"desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
"rules": [{
"action": "allow",
"page": "*"
}]
}
\ No newline at end of file
const formatTime = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
}
const formatNumber = n => {
n = n.toString()
return n[1] ? n : `0${n}`
}
module.exports = {
formatTime
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment