嘉兴 做企业网站,中国保险行业协会网站,wordpress汉化模板,灰色词快速排名方法一、前言
模拟编辑器或者模拟输入框中文字啪啦啪啦输入的效果#xff0c;往往能够吸引人们的眼球#xff0c;让用户的注意力聚焦在输入的内容上#xff0c;本文将和大家探讨打字机效果的实现方式以及应用。Demo基于API12。
二、思路
拆分开来很简单#xff0c;将字符串拆…一、前言
模拟编辑器或者模拟输入框中文字啪啦啪啦输入的效果往往能够吸引人们的眼球让用户的注意力聚焦在输入的内容上本文将和大家探讨打字机效果的实现方式以及应用。Demo基于API12。
二、思路
拆分开来很简单将字符串拆分只需把要展示的文本进行切割使用定时器不断追加文字即可。光标我们可以使用自带的TextArea来实现。
效果如下 三、数据源
随便抄了一段文本 private targetTxt: string 碧海青天夜夜心闲云潭影日悠悠。花开堪折直须折莫待无花空折枝。江南好风景旧曾谙。日出江花红胜火春来江水绿如蓝。能不忆江南松风吹解带山月照弹琴。遥望洞庭山水翠白银盘里一青螺。人生若只如初见何事秋风悲画扇浮生若梦为欢几何长风破浪会有时直挂云帆济沧海。岁月不居时节如流。人生天地间若白驹过隙忽然而已。愿逐月华流照君千里共婵娟。 分割 aboutToAppear(): void {this.targetTxtArray this.targetTxt.split();}准备一个State变量用于显示UI State currentTxt: string 四、TextArea
使用TextArea要面对的就是输入框是有焦点和事件以及配套的键盘的同时又需要光标。如下 TextArea({text: this.currentTxt}).width(auto).height(auto).animation({ duration: 200, curve: Curve.Smooth }).focusable(true).defaultFocus(true).enableKeyboardOnFocus(false).fontColor(#fefae0).caretColor(#d4a373).backgroundColor(#ccd5ae).hitTestBehavior(HitTestMode.None)使用focusable(true)、defaultFocus(true)来获取焦点达到显示光标的效果。enableKeyboardOnFocus(false) 用于限制它弹出键盘hitTestBehavior(HitTestMode.None)则屏蔽了所有的事件
我们得到了一个干净的有光标的无法操作的输入框
五、setInterval
显然需要一个定时器来间隔添加文字。 State currentProgress: number 0State inputStepChar: number 1private inputTxt(step: number) {if (this.intervalId ! -1) {clearInterval(this.intervalId)this.intervalId -1}this.intervalId setInterval(() {if (this.currentProgress this.targetTxtArray.length - 1) {clearInterval(this.intervalId)break} else {this.currentTxt this.targetTxtArray[ this.currentProgress]}}, step)}因为可能被多次调用我们需要存一个定时器ID在后续的触发中将定时器清除。
step就是输入的间隔了也就是输入速度。
每间隔一次就在数组中取一个字符串直到取完。
六、删除
因为有输入那就可以有删除也很简单。反过来就行了 private removeTxt(step: number) {if (this.intervalId ! -1) {clearInterval(this.intervalId)this.intervalId -1}this.intervalId setInterval(() {if (this.currentProgress 0) {clearInterval(this.intervalId)} else {this.currentProgress--this.currentTxt this.currentTxt.substring(0, this.currentTxt.length - 1);}}, step)}每间隔一次就在currentTxt中移除最后一个字符并currentProgress递减直到删完。
七、删除、添加多个
默认是一个个增加一个个删除。多个的话我们直接点。使用一个For循环将原有的逻辑套进去就好了。 private inputTxt(step: number) {if (this.intervalId ! -1) {clearInterval(this.intervalId)this.intervalId -1}this.intervalId setInterval(() {for (let index 0; index this.inputStepChar; index) {if (this.currentProgress this.targetTxtArray.length - 1) {clearInterval(this.intervalId)break} else {this.currentTxt this.targetTxtArray[ this.currentProgress]}}}, step)}inputStepChar就是每次改变的字符数了想多少就多少。
八、最终代码 let maxSpeed: number 1000let minSpeed: number 50let minStepChar: number 1let maxStepChar: number 10/*** Des* Author zyc* Date 2024/5/30*/Componentexport struct TypeWriterComponent {private targetTxt: string 碧海青天夜夜心闲云潭影日悠悠。花开堪折直须折莫待无花空折枝。江南好风景旧曾谙。日出江花红胜火春来江水绿如蓝。能不忆江南松风吹解带山月照弹琴。遥望洞庭山水翠白银盘里一青螺。人生若只如初见何事秋风悲画扇浮生若梦为欢几何长风破浪会有时直挂云帆济沧海。岁月不居时节如流。人生天地间若白驹过隙忽然而已。愿逐月华流照君千里共婵娟。 private intervalId: number -1private targetTxtArray: string[] []private defInputSpeed: number 200private defRemoveSpeed: number 100State inputStepChar: number 1State removeStepChar: number 1State currentProgress: number 0State currentTxt: string State inputSpeed: number 0State removeSpeed: number 0aboutToAppear(): void {this.targetTxtArray this.targetTxt.split();this.defRemoveSpeed Math.abs(this.defRemoveSpeed - maxSpeed) minSpeedthis.defInputSpeed Math.abs(this.defInputSpeed - maxSpeed) minSpeedthis.removeSpeed this.defRemoveSpeedthis.inputSpeed this.defInputSpeed}private inputTxt(step: number) {if (this.intervalId ! -1) {clearInterval(this.intervalId)this.intervalId -1}this.intervalId setInterval(() {zfor (let index 0; index this.inputStepChar; index) {if (this.currentProgress this.targetTxtArray.length - 1) {clearInterval(this.intervalId)break} else {this.currentTxt this.targetTxtArray[ this.currentProgress]}}}, step)}private removeTxt(step: number) {if (this.intervalId ! -1) {clearInterval(this.intervalId)this.intervalId -1}this.intervalId setInterval(() {for (let index 0; index this.removeStepChar; index) {if (this.currentProgress 0) {clearInterval(this.intervalId)break} else {this.currentProgress--this.currentTxt this.currentTxt.substring(0, this.currentTxt.length - 1);}}}, step)}build() {Column({ space: 10 }) {TextArea({text: this.currentTxt}).width(auto).height(auto).animation({ duration: 200, curve: Curve.Smooth }).focusable(true).defaultFocus(true).enableKeyboardOnFocus(false).fontColor(#fefae0).caretColor(#d4a373).backgroundColor(#ccd5ae).hitTestBehavior(HitTestMode.None)Blank()Row() {Text(输入长度).fontColor(Color.Black)Slider({style: SliderStyle.InSet,value: 1,step: 1,min: minStepChar,max: maxStepChar,}).layoutWeight(1).showSteps(true).stepSize(3).showTips(true, ${this.inputStepChar}).selectedColor(#f07167).trackColor(#fdfcdc).stepColor(#fed9b7).onChange(value {this.inputStepChar valuethis.inputTxt(this.inputSpeed)})}Row() {Text(删除长度).fontColor(Color.Black)Slider({style: SliderStyle.InSet,value: 1,step: 1,min: minStepChar,max: maxStepChar,}).layoutWeight(1).showSteps(true).stepSize(3).showTips(true, ${this.removeStepChar}).selectedColor(#77bfa3).trackColor(#edeec9).stepColor(#bfd8bd).onChange(value {this.removeStepChar valuethis.removeTxt(this.inputSpeed)})}Row() {Text(输入速度).fontColor(Color.Black)Slider({style: SliderStyle.InSet,value: this.defInputSpeed,step: 50,min: minSpeed,max: maxSpeed,}).layoutWeight(1).showSteps(true).stepSize(3).showTips(true, ${this.inputSpeed}).selectedColor(#588157).trackColor(#dad7cd).stepColor(#a3b18a).onChange(value {this.inputSpeed Math.abs(value - maxSpeed) minSpeedthis.inputTxt(this.inputSpeed)})}Row() {Text(删除速度).fontColor(Color.Black)Slider({style: SliderStyle.InSet,value: this.defRemoveSpeed,step: 50,min: minSpeed,max: maxSpeed,}).layoutWeight(1).showSteps(true).stepSize(3).showTips(true, ${this.removeSpeed}).selectedColor(#ddb892).trackColor(#ede0d4).stepColor(#e6ccb2).onChange(value {this.removeSpeed Math.abs(value - maxSpeed) minSpeedthis.removeTxt(this.removeSpeed)})}Row({ space: 30 }) {Button(输出).onClick(() {this.inputTxt(this.inputSpeed)})Button(撤回).onClick(() {this.removeTxt(this.removeSpeed)})}}.padding(horizontalBottom(20, 40)).size(matchSize)}}最后
有很多小伙伴不知道学习哪些鸿蒙开发技术不知道需要重点掌握哪些鸿蒙应用开发知识点而且学习时频繁踩坑最终浪费大量时间。所以有一份实用的鸿蒙HarmonyOS NEXT资料用来跟着学习是非常有必要的。
鸿蒙HarmonyOS Next全套学习资料←点击领取安全链接放心点击
这份鸿蒙HarmonyOS NEXT资料包含了鸿蒙开发必掌握的核心知识要点内容包含了ArkTS、ArkUI开发组件、Stage模型、多端部署、分布式应用开发、音频、视频、WebGL、OpenHarmony多媒体技术、Napi组件、OpenHarmony内核、Harmony南向开发、鸿蒙项目实战等等鸿蒙HarmonyOS NEXT技术知识点。
希望这一份鸿蒙学习资料能够给大家带来帮助有需要的小伙伴自行领取限时开源先到先得~无套路领取
鸿蒙HarmonyOS NEXT最新学习路线 有了路线图怎么能没有学习资料呢小编也准备了一份联合鸿蒙官方发布笔记整理收纳的一套系统性的鸿蒙OpenHarmony 学习手册共计1236页与鸿蒙OpenHarmony 开发入门教学视频内容包含ArkTS、ArkUI、Web开发、应用模型、资源分类…等知识点。
获取以上完整版高清学习路线请点击→纯血版全套鸿蒙HarmonyOS学习资料
HarmonyOS Next 最新全套视频教程 《鸿蒙 (OpenHarmony)开发基础到实战手册》
OpenHarmony北向、南向开发环境搭建 《鸿蒙开发基础》
ArkTS语言安装DevEco Studio运用你的第一个ArkTS应用ArkUI声明式UI开发.……
《鸿蒙开发进阶》
Stage模型入门网络管理数据管理电话服务分布式应用开发通知与窗口管理多媒体技术安全技能任务管理WebGL国际化开发应用测试DFX面向未来设计鸿蒙系统移植和裁剪定制…… 《鸿蒙进阶实战》
ArkTS实践UIAbility应用网络案例…… 大厂面试必问面试题 鸿蒙南向开发技术 鸿蒙APP开发必备 鸿蒙生态应用开发白皮书V2.0PDF 获取以上完整鸿蒙HarmonyOS学习资料请点击→纯血版全套鸿蒙HarmonyOS学习资料
总结 总的来说华为鸿蒙不再兼容安卓对中年程序员来说是一个挑战也是一个机会。只有积极应对变化不断学习和提升自己他们才能在这个变革的时代中立于不败之地。 文章转载自: http://www.morning.whothehellami.com.gov.cn.whothehellami.com http://www.morning.zrgsg.cn.gov.cn.zrgsg.cn http://www.morning.hlshn.cn.gov.cn.hlshn.cn http://www.morning.mhnr.cn.gov.cn.mhnr.cn http://www.morning.ctfwl.cn.gov.cn.ctfwl.cn http://www.morning.bfgpn.cn.gov.cn.bfgpn.cn http://www.morning.kpgbz.cn.gov.cn.kpgbz.cn http://www.morning.byzpl.cn.gov.cn.byzpl.cn http://www.morning.cthrb.cn.gov.cn.cthrb.cn http://www.morning.rxrw.cn.gov.cn.rxrw.cn http://www.morning.xgmf.cn.gov.cn.xgmf.cn http://www.morning.qhnmj.cn.gov.cn.qhnmj.cn http://www.morning.mqzcn.cn.gov.cn.mqzcn.cn http://www.morning.knnc.cn.gov.cn.knnc.cn http://www.morning.lbrwm.cn.gov.cn.lbrwm.cn http://www.morning.ai-wang.cn.gov.cn.ai-wang.cn http://www.morning.hbywj.cn.gov.cn.hbywj.cn http://www.morning.tbjb.cn.gov.cn.tbjb.cn http://www.morning.kwqt.cn.gov.cn.kwqt.cn http://www.morning.qqklk.cn.gov.cn.qqklk.cn http://www.morning.grbgn.cn.gov.cn.grbgn.cn http://www.morning.twfdm.cn.gov.cn.twfdm.cn http://www.morning.wlfxn.cn.gov.cn.wlfxn.cn http://www.morning.qkzdc.cn.gov.cn.qkzdc.cn http://www.morning.homayy.com.gov.cn.homayy.com http://www.morning.nrwr.cn.gov.cn.nrwr.cn http://www.morning.zylrk.cn.gov.cn.zylrk.cn http://www.morning.rtzd.cn.gov.cn.rtzd.cn http://www.morning.mnjwj.cn.gov.cn.mnjwj.cn http://www.morning.nqrlz.cn.gov.cn.nqrlz.cn http://www.morning.wchcx.cn.gov.cn.wchcx.cn http://www.morning.cnlmp.cn.gov.cn.cnlmp.cn http://www.morning.lsgjf.cn.gov.cn.lsgjf.cn http://www.morning.yxshp.cn.gov.cn.yxshp.cn http://www.morning.kfqzd.cn.gov.cn.kfqzd.cn http://www.morning.sfphz.cn.gov.cn.sfphz.cn http://www.morning.wnhsw.cn.gov.cn.wnhsw.cn http://www.morning.ptqpd.cn.gov.cn.ptqpd.cn http://www.morning.tdfyj.cn.gov.cn.tdfyj.cn http://www.morning.bmsqq.cn.gov.cn.bmsqq.cn http://www.morning.khtjn.cn.gov.cn.khtjn.cn http://www.morning.pdgqf.cn.gov.cn.pdgqf.cn http://www.morning.mcqhb.cn.gov.cn.mcqhb.cn http://www.morning.csnmd.cn.gov.cn.csnmd.cn http://www.morning.bbyqz.cn.gov.cn.bbyqz.cn http://www.morning.mkkcr.cn.gov.cn.mkkcr.cn http://www.morning.ynrzf.cn.gov.cn.ynrzf.cn http://www.morning.kbgzj.cn.gov.cn.kbgzj.cn http://www.morning.ykwgl.cn.gov.cn.ykwgl.cn http://www.morning.ygkq.cn.gov.cn.ygkq.cn http://www.morning.sfswj.cn.gov.cn.sfswj.cn http://www.morning.dmcqy.cn.gov.cn.dmcqy.cn http://www.morning.nfmlt.cn.gov.cn.nfmlt.cn http://www.morning.bwkhp.cn.gov.cn.bwkhp.cn http://www.morning.jwbfj.cn.gov.cn.jwbfj.cn http://www.morning.zkdbx.cn.gov.cn.zkdbx.cn http://www.morning.hnrdtz.com.gov.cn.hnrdtz.com http://www.morning.dzqyn.cn.gov.cn.dzqyn.cn http://www.morning.tyrlk.cn.gov.cn.tyrlk.cn http://www.morning.rqfkh.cn.gov.cn.rqfkh.cn http://www.morning.qwgct.cn.gov.cn.qwgct.cn http://www.morning.gdpai.com.cn.gov.cn.gdpai.com.cn http://www.morning.zmtrk.cn.gov.cn.zmtrk.cn http://www.morning.gbtty.cn.gov.cn.gbtty.cn http://www.morning.zcckq.cn.gov.cn.zcckq.cn http://www.morning.rbkml.cn.gov.cn.rbkml.cn http://www.morning.dkzrs.cn.gov.cn.dkzrs.cn http://www.morning.kqlrl.cn.gov.cn.kqlrl.cn http://www.morning.dhqg.cn.gov.cn.dhqg.cn http://www.morning.kkhf.cn.gov.cn.kkhf.cn http://www.morning.wqpsf.cn.gov.cn.wqpsf.cn http://www.morning.ffbp.cn.gov.cn.ffbp.cn http://www.morning.smkxm.cn.gov.cn.smkxm.cn http://www.morning.hyhzt.cn.gov.cn.hyhzt.cn http://www.morning.hctgn.cn.gov.cn.hctgn.cn http://www.morning.lfmwt.cn.gov.cn.lfmwt.cn http://www.morning.xgcwm.cn.gov.cn.xgcwm.cn http://www.morning.mpnff.cn.gov.cn.mpnff.cn http://www.morning.bmyrl.cn.gov.cn.bmyrl.cn http://www.morning.dtlqc.cn.gov.cn.dtlqc.cn