微信小程序案例-03翻页时钟-3

微信小程序实战系列

  • 《微信小程序实战-01翻页时钟-1》
  • 《微信小程序实战-02翻页时钟-2》

文章目录

  • 微信小程序实战系列
  • 前言
  • 动态翻页效果实现
    • clock.wxml
    • clock.wxss
    • clock.js
    • 运行效果
  • 总结

前言

本文继续完成最后一个部分“动态翻页效果”。

动态翻页效果实现

clock.wxml

<view class="container">
<view class="clock-container"><view class="flip-container"><block wx:for="{{timeArr}}" wx:for-item="unit" wx:for-index="unitIndex" wx:key="unitIndex"><view class="flip-items"><block wx:for="{{unit.max+1}}" wx:for-item="item" wx:for-index="index" wx:key="index"><view class="{{['item',(unit.current==index)?'current':'',(unit.current-1==index||index==unit.max&&unit.current==0)?'past':'']}}"><view class="up"><view class="inner">{{index}}</view><view class="shadow"></view></view><view class="down"><view class="inner">{{index}}</view><view class="shadow"></view></view></view></block></view></block></view>
</view>
</view>

clock.wxss

.flip-container {display: flex;justify-content: center;position: relative;padding: 0 20rpx;
}.flip-items {position: relative;width: 90rpx;height: 145rpx;font-size: 128rpx;font-weight: bold;border-radius: 10rpx;border: 1rpx solid rgba(121, 121, 121, 0.384);box-shadow: 0 2rpx 18rpx rgba(0, 0, 0, 0.7);
}.flip-container .flip-items:nth-of-type(2n+1) {margin-right: 12rpx;
}.flip-container .flip-items:nth-of-type(2),
.flip-container .flip-items:nth-of-type(4) {margin-right: 36rpx;
}.flip-container .flip-items:nth-of-type(2)::after,
.flip-container .flip-items:nth-of-type(4)::after,
.flip-container .flip-items:nth-of-type(2)::before,
.flip-container .flip-items:nth-of-type(4)::before {position: absolute;right: -18rpx;content: '';transform: translateX(50%);width: 25rpx;height: 25rpx;border-radius: 50%;box-shadow: rgba(0, 0, 0, 0.7) 1px 1px 5px;background-color: rgba(0, 0, 0, 0.801);
}.flip-container .flip-items:nth-of-type(2)::before,
.flip-container .flip-items:nth-of-type(4)::before {top: 25%;
}.flip-container .flip-items:nth-of-type(2)::after,
.flip-container .flip-items:nth-of-type(4)::after {bottom: 25%;
}.item {position: absolute;top: 0;left: 0;right: 0;bottom: 0;z-index: 1;
}.item::before {position: absolute;content: '';top: 75rpx;width: 100%;height: 5rpx;background-color: rgba(0, 0, 0, 0.5);z-index: 9;
}.flip-container .flip-items .item .up,
.flip-container .flip-items .item .down {position: absolute;left: 0;right: 0;height: 50%;overflow: hidden;
}/* 设置transform的原点 */
.up {transform-origin: 50% 100%;top: 0;
}/* 设置transform的原点 */
.flip-container .flip-items .item .down {transform-origin: 50% 0%;bottom: 0;
}.flip-container .flip-items .item .inner {position: absolute;width: 100%;height: 145rpx;color: #252525;left: 0;line-height: 145rpx;text-align: center;text-shadow: 0 2rpx 4rpx rgb(0, 0, 0);border-radius: 10rpx;background-color: #55e3e3;
}.flip-container .flip-items .item .up .inner {top: 0;
}.flip-container .flip-items .item .down .inner {bottom: 0;
}.flip-container .flip-items .item .up .shadow {border-top-left-radius: 10rpx;border-top-right-radius: 10rpx;
}.flip-container .flip-items .item .down .shadow {border-bottom-left-radius: 10rpx;border-bottom-right-radius: 10rpx;
}.flip-container .flip-items .item.past {z-index: 3;
}/*  current time keep top z-index:4 */
.flip-container .flip-items .item.current {animation: highter-level 0.5s 0.5s linear forwards;z-index: 2;
}/* 前一秒的上半页,旋转 0~-90deg */
.flip-container .flip-items .item.past .up {animation: flip-past-up 0.5s linear both;
}/* 当前秒的下半页,旋转90~0 */
.flip-container .flip-items .item.current .down {animation: flip-current-down 0.5s 0.5s linear both;
}@keyframes flip-current-down {from {transform: rotateX(90deg);}to {transform: rotateX(0deg);}
}
@keyframes flip-past-up {from {transform: rotateX(0deg);}to {transform: rotateX(-90deg);}
}@keyframes highter-level {from {z-index: 4;}to {z-index: 4;}
}.flip-container .flip-items .item .shadow {position: absolute;width: 100%;height: 100%;
}/* show 渐变 */
.flip-container .flip-items .item.past .up .shadow {background: linear-gradient(rgba(0, 0, 0, 0.1) 0%, #000 100%);animation: show 0.5s linear both;
}/* show 渐变 */
.flip-container .flip-items .item.past .down .shadow {background: linear-gradient(#000 0%, rgba(0, 0, 0, 0.1) 100%);animation: show 0.5s linear both;
}/* hide 渐变 */.flip-container .flip-items .item.current .up .shadow {background: linear-gradient(rgba(0, 0, 0, 0.1) 0%, #000 100%);animation: hide 0.5s 0.3s linear both;
}.flip-container .flip-items .item.current .down .shadow {background: linear-gradient(#000 0%, rgba(0, 0, 0, 0.1) 100%);animation: hide 0.5s 0.3s linear both;
}@keyframes show {from {opacity: 0;}to {opacity: 1;}
}@keyframes hide {from {opacity: 1;}to {opacity: 0;}
}

clock.js


Page({data: {},onLoad: function () {this.setTimeRunner()},setTimeRunner: function () {this.timeRunner = setInterval(() => {this.getTimeStr();this.getTimeArr();}, 1000);},getTimeStr: function () {let that = this;var time = new Date();var hour = ('0' + time.getHours()).slice(-2);var minute = ('0' + time.getMinutes()).slice(-2);var second = ('0' + time.getSeconds()).slice(-2);var timeStr = (hour + minute + second).split('');that.setData({timeStr:timeStr})},getTimeArr: function () {var timeArr = this.data.timeStr.map(function (element, index) {var max;if (index & 1 == 1) { max = 9;} else if (index == 0) { max = 2;} else if (index == 2) { max = 5;} else if (index == 4) { max = 5;}var current = Number(element)return {max: max,current: current};})this.setData({timeArr:timeArr})},beforeDestroy:function () {clearInterval(this.timeRunner);},onUnload: function () {this.beforeDestroy()}
})

运行效果

点击翻页时钟运行效果

总结

本项目的综合性较强,对wxss、wxml、js的综合运用需要较为熟悉,是一个非常好的练手小项目。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/616766.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

查看SQL Server的表字段类型、长度、描述以及是否可为null

文章目录 初步理解小步测试组合一下参考文章有更详细评述 继续理解得到大部分信息 本文参考&#xff1a;https://blog.csdn.net/josjiang1/article/details/80558068。 也可以直接点击这里文章链接&#xff1a; sql server查询表结构&#xff08;字段名&#xff0c;数据类型&a…

面试常见知识点--树的遍历

一、前序遍历 算法流程: 1.先申请一个栈&#xff0c;记为stk。 2&#xff0e;然后将根节点压入stk中。 3&#xff0e;每次从stk中弹出栈顶节点&#xff0c;记为cur&#xff0c;然后打印cur的值。如果cur的右子树不为空&#xff0c;将cur的右子树压入stk中。如果cur的左子树不为…

CSS 中的伪装大师:伪类和伪元素的奇妙世界

&#x1f90d; 前端开发工程师&#xff08;主业&#xff09;、技术博主&#xff08;副业&#xff09;、已过CET6 &#x1f368; 阿珊和她的猫_CSDN个人主页 &#x1f560; 牛客高级专题作者、在牛客打造高质量专栏《前端面试必备》 &#x1f35a; 蓝桥云课签约作者、已在蓝桥云…

JavaScript中的文件下载

在JavaScript中&#xff0c;实现文件下载的功能可以通过多种方式实现&#xff0c;以下是一些常见的方法&#xff1a; 方法 1&#xff1a;使用HTML5的<a>标签 如果你已经有了一个文件的URL&#xff0c;可以简单地使用一个 <a> 标签并设置download属性。这可以通过…

双指针问题——求只包含两个元素的最长连续子序列(子数组)

一&#xff0c;题目描述 你正在探访一家农场&#xff0c;农场从左到右种植了一排果树。这些树用一个整数数组 fruits 表示&#xff0c;其中 fruits[i] 是第 i 棵树上的水果 种类 。 你想要尽可能多地收集水果。然而&#xff0c;农场的主人设定了一些严格的规矩&#xff0c;你必…

代码随想录 Leetcode203. 移除链表元素

题目&#xff1a; 代码(首刷看解析 2024年1月11日&#xff09;&#xff1a; class Solution { public:ListNode* removeElements(ListNode* head, int val) {if(headnullptr) return nullptr;ListNode* BeforeHead new ListNode(0,head);ListNode* temp BeforeHead;while(te…

【正点原子STM32连载】第三十一章 待机模式实验 摘自【正点原子】APM32E103最小系统板使用指南

1&#xff09;实验平台&#xff1a;正点原子APM32E103最小系统板 2&#xff09;平台购买地址&#xff1a;https://detail.tmall.com/item.htm?id609294757420 3&#xff09;全套实验源码手册视频下载地址&#xff1a; http://www.openedv.com/docs/boards/xiaoxitongban 第三…

逆向分析爬取网页动态

本例子以爬取人民邮电出版社网页新书的信息为例 由于页面是动态的&#xff0c;信息会不停地更新&#xff0c;所以不同时间的爬取结果会不同。

银行的压力测试如何进行?

为什么要进行压力风险测试&#xff1f; 压力风险测试的最终目的是测试银行在极度恶劣的市场环境中是否有足够的资本维持运转。 题主链接中的一级资本充足率(Tier 1 capital ratio) 亦即衡量标准&#xff0c;这个数字越大&#xff0c;表明银行资本约充裕&#xff0c;可以在停止…

Kubernetes (七) service(微服务)及Ingress-nginx

官网地址&#xff1a; 服务&#xff08;Service&#xff09; | Kuberneteshttps://v1-24.docs.kubernetes.io/zh-cn/docs/concepts/services-networking/service/ 一 . 网络通信原理 …

独立安全 | 企业选择系统定制化开发的最主要优势

随着信息化和互联网的迅猛发展&#xff0c;网络经济给企业带来了巨大的好处。越来越多的企业选择利用第三方平台来建设网店系统&#xff0c;这也导致竞争变得越来越激烈。另一方面&#xff0c;选择定制开发独立商城对企业也有很多好处。这些好处包括以下几点&#xff1a; 1.独…

2024年前端面试中JavaScript的30个高频面试题之基础知识

中级 高级知识 充分准备你的下一个JavaScript面试,增强信心! 无论你是老手还是刚进入技术行业,这份2024年必备资源都将帮助你复习核心概念,从基本语言特性到高级主题。 在本文中,我汇总了30个最关键的JavaScript面试题以及详细的答案和代码示例。 深入探索这宝贵的收藏,以确…

NAND Separate Command Address (SCA) 接口数据传输解读

在采用Separate Command Address (SCA) 接口的存储产品中&#xff0c;DQ input burst和DQ output burst又是什么样的策略呢&#xff1f; DQ Input Burst: 在读取操作期间&#xff0c;数据以一种快速并行的方式通过DQ总线传送到控制器。在SCA接口下&#xff0c;虽然命令和地址信…

关于Python里xlwings库对Excel表格的操作(三十一)

这篇小笔记主要记录如何【如何使用“Chart类”、“Api类"和“Axes函数”设置绘图区外框线型、颜色、粗细及填充颜色】。前面的小笔记已整理成目录&#xff0c;可点链接去目录寻找所需更方便。 【目录部分内容如下】【点击此处可进入目录】 &#xff08;1&#xff09;如何安…

【附源码】基于SSM+Java的题库管理系统的设计与实现

基于SSMJava的题库管理系统的设计与实现 &#x1f345; 作者主页 央顺技术团队 &#x1f345; 欢迎点赞 &#x1f44d; 收藏 ⭐留言 &#x1f4dd; &#x1f345; 文末获取源码联系方式 &#x1f4dd; 环境配置&#xff1a; Jdk1.8 Tomcat7.0 Mysql HBuilderX&#xff08;We…

JAVA序列化

对象序列化&#xff08;object serialization&#xff09;是java支持的通用机制&#xff0c;可以将任何对象写出到流中&#xff0c;并在之后将其回读。简单来说&#xff0c;就是可以将对象数据保存为文件&#xff0c;甚至可以通过网络传输&#xff0c;在这之后或者别的主机上恢…

企业如何开展百科营销?需要创建哪些百科词条?

在营销工作实践中&#xff0c;小马识途营销顾问经常接到关于百科营销的咨询&#xff0c;现整理了最受关注的九个问题分享给热爱营销工作的小伙伴。 一、什么是百科营销&#xff1f; 百科营销是借助百科知识传播&#xff0c;可以将企业、品牌、人物所拥有的对用户有价值的信息&a…

Redis的优化

1 Redis的高可用 1.1 高可用的定义 在web服务器中&#xff0c;高可用是指服务器可以正常访问的时间&#xff0c;衡量的标准是在多长时间内可以提供正常服务&#xff08;99.9%、99.99%、99.999%等等&#xff09;。 但是在Redis语境中&#xff0c;高可用的含义似乎要宽泛一些&…

RTSP网络视频协议

一.RTSP网络视频协议介绍 RTSP是类似HTTP的应用层协议&#xff0c;一个典型的流媒体框架网络体系可参考下图&#xff0c;其中rtsp主要用于控制命令&#xff0c;rtcp主要用于视频质量的反馈&#xff0c;rtp用于视频、音频流从传输。 1、RTSP&#xff08;Real Time Streaming P…

【群晖NAS】记一次FRP报错:login to server failed: connection write timeout

报错如下&#xff1a; rongfuDS224plus:~/fff/frp$ ./frpc -c ./frpc.toml 2024/01/12 23:08:31 [I] [root.go:139] start frpc service for config file [./frpc.toml] 2024/01/12 23:08:41 [W] [service.go:131] login to server failed: i/o deadline reached 2024/01/12 2…