鸿蒙API14开发【div】JS组件
权限列表
样式
除支持组件[通用样式]外,还支持如下样式:
事件
除支持[通用事件]外,还支持如下事件:
方法
除支持[通用方法外,还支持如下方法:
表1 ScrollOffset6+
表2 ScrollParam6+
示例
- 
Flex样式
html/* xxx.css */.container { flex-direction: column; justify-content: center; align-items: center; width: 454px; height: 454px;}.flex-box { justify-content: space-around; align-items: center; width: 400px; height: 140px; background-color: #ffffff;}.flex-item { width: 120px; height: 120px; border-radius: 16px;}.color-primary { background-color: #007dff;}.color-warning { background-color: #ff7500;}.color-success { background-color: #41ba41;}css
 - 
Flex Wrap样式
html/* xxx.css */.container { flex-direction: column; justify-content: center; align-items: center; width: 454px; height: 454px;}.flex-box { justify-content: space-around; align-items: center; flex-wrap: wrap; width: 300px; height: 250px; background-color: #ffffff;}.flex-item { width: 120px; height: 120px; border-radius: 16px;}.color-primary { background-color: #007dff;}.color-warning { background-color: #ff7500;}.color-success { background-color: #41ba41;}css
 - 
Grid样式
html/* xxx.css */.common { width: 400px; height: 400px; background-color: #ffffff; align-items: center; justify-content: center; margin: 24px;}.grid-parent { display: grid; grid-template-columns: 35% 35%; grid-columns-gap: 24px; grid-rows-gap: 24px; grid-template-rows: 35% 35%;}.grid-child { width: 100%; height: 100%; border-radius: 8px;}.grid-left-top { grid-row-start: 0; grid-column-start: 0; grid-row-end: 0; grid-column-end: 0; background-color: #3f56ea;}.grid-left-bottom { grid-row-start: 1; grid-column-start: 0; grid-row-end: 1; grid-column-end: 0; background-color: #00aaee;}.grid-right-top { grid-row-start: 0; grid-column-start: 1; grid-row-end: 0; grid-column-end: 1; background-color: #00bfc9;}.grid-right-bottom { grid-row-start: 1; grid-column-start: 1; grid-row-end: 1; grid-column-end: 1; background-color: #47cc47;}css
 - 
拖拽7+
<div class=\"content\" ondragstart=\"dragstart\" ondrag=\"drag\" ondragend=\"dragend\" style=\"position: absolute;left: {{left}};top: {{top}};\"> 
 /* xxx.css */ .container { flex-direction: column; width: 100%; height: 100%; } .content { width: 200px; height: 200px; background-color: red; }css
// xxx.jsimport promptAction from \'@ohos.promptAction\';export default { data:{ left:0, top:0, }, dragstart(e){ prompt.showToast({ message: \'Start to be dragged\' }) }, drag(e){ this.left = e.globalX; this.top = e.globalY; }, dragend(e){ promptAction.showToast({ message: \'End Drag\' }) }}js

 <div class=\"content\" ondrag=\"drag\" style=\"position: absolute;left: {{left}};top: {{top}};\">  /* xxx.css */.container { flex-direction: column; width: 100%; position: relative; max-width: 100%;}.content{ width: 200px; height: 200px; background-color: red; position: absolute;}css
// xxx.jsimport promptAction from \'@ohos.promptAction\';export default { data:{ left:0, top:0, }, drag(e){ this.left = e.globalX; this.top = e.globalY; }, dragenter(e){ promptAction.showToast({ message: \'enter\' }) }, dragover(e){ promptAction.showToast({ message: \'over\' }) }, dragleave(e){ promptAction.showToast({ message: \'leave\' }) }, drop(e){ promptAction.showToast({ message: \'drop\' }) }}js

手指捏合7+
  html
/* xxx.css */.container { flex-direction: column; justify-content: center; align-items: center; width: 454px; height: 454px;}.content { width: 400px; height: 400px; background-color: aqua; margin: 30px;}css
// xxx.jsimport promptAction from \'@ohos.promptAction\';export default { pinchstart(e){ promptAction.showToast({ message: \'pinchstart!!!\' }) }, pinchupdate(e){ promptAction.showToast({ message: \'Two-finger pinch update\' }) }, pinchend(e){ promptAction.showToast({ message: \'Finished with two fingers pinching\' }) }, pinchcancel(e){ promptAction.showToast({ message: \'Finger pinching is interrupted\' }) }}js

加入鸿蒙学习阵营!
除了本文,面费领《HarmonyOS应用开发》+《鸿蒙openharmony系统开发大全》 等入门进阶资料!关注我的CSDN主页,持续获取:
最新鸿蒙技术文章
独家项目实战教程
免费直播/训练营信息
👉 下方资源区已为你备好!


