当前位置:   article > 正文

HarmonyOS应用开发-圆角list实现_鸿蒙js list设置item背景圆角

鸿蒙js list设置item背景圆角

效果展示:

Hml

  1. <div class="container">
  2. <list class="topList_corner_round_bg" scrolleffect="no">
  3. <list-item for="{{ topList }}" class="{{ $item.cls }}" onclick="onTopListItemClick($idx)" id="{{ $idx }} ">
  4. <stack>
  5. <div style="flex-direction : row;">
  6. <stack class="div_icon">
  7. <div class="item_icon" style="background-color : {{ $item.iconColor }}"></div>
  8. <text class="txt_title" style="color : {{ $item.txtColor }};">{{ $item.indexTxt }}</text>
  9. </stack>
  10. <div class="div_right">
  11. <text class="item_title">{{ $item.title }}</text>
  12. <text class="item_title item_desc">{{ $item.desc }}</text>
  13. </div>
  14. </div>
  15. <div class="div_arrow">
  16. <image src="/common/images/list_arrow_gray.png" class="item_arrow"/>
  17. </div>
  18. </stack>
  19. </list-item>
  20. </list>
  21. <list class="middleList_corner_round_bg">
  22. <list-item for="{{ middleList }}" class="{{ $item.cls }}" onclick="onMiddleListItemClick($idx)" id="{{ $idx }}">
  23. <stack>
  24. <div style="flex-direction : row;">
  25. <stack class="div_icon">
  26. <div class="item_icon" style="background-color : {{ $item.iconColor }}"></div>
  27. <text class="txt_title" style="color : {{ $item.txtColor }};">{{ $item.indexTxt }}</text>
  28. </stack>
  29. <div class="div_right">
  30. <text class="item_title">{{ $item.title }}</text>
  31. <text class="item_title item_desc">{{ $item.desc }}</text>
  32. </div>
  33. </div>
  34. <div class="div_arrow">
  35. <image src="/common/images/list_arrow_gray.png" class="item_arrow"/>
  36. </div>
  37. </stack>
  38. </list-item>
  39. </list>
  40. <list class="bottomList_corner_round_bg">
  41. <list-item for="{{ bottomList }}" class="{{ $item.cls }}" onclick="onBottomListItemClick($idx)" id="{{ $idx }}">
  42. <stack>
  43. <div style="flex-direction : row;">
  44. <stack class="div_icon">
  45. <div class="item_icon" style="background-color : {{ $item.iconColor }}"></div>
  46. <text class="txt_title" style="color : {{ $item.txtColor }};">{{ $item.indexTxt }}</text>
  47. </stack>
  48. <div class="div_right">
  49. <text class="item_title">{{ $item.title }}</text>
  50. <text class="item_title item_desc">{{ $item.desc }}</text>
  51. </div>
  52. </div>
  53. <div class="div_arrow">
  54. <image src="/common/images/list_arrow_gray.png" class="item_arrow"/>
  55. </div>
  56. </stack>
  57. </list-item>
  58. </list>
  59. </div>

 Css

  1. .container {
  2. flex-direction: column;
  3. align-items: center;
  4. background-color: #5e7c85;
  5. padding-top: 52px;
  6. }
  7. .topList_corner_round_bg {
  8. width: 100%;
  9. height: 240px;
  10. border: 1px solid #000000;
  11. text-align: center;
  12. margin-left: 10px;
  13. margin-right: 10px;
  14. border-radius: 8px;
  15. divider-color: #000000;
  16. divider-height: 1px;
  17. }
  18. .middleList_corner_round_bg {
  19. width: 100%;
  20. height: 160px;
  21. border: 1px solid #000000;
  22. text-align: center;
  23. margin-top: 10px;
  24. margin-left: 10px;
  25. margin-right: 10px;
  26. border-radius: 8px;
  27. divider-color: #000000;
  28. divider-height: 1px;
  29. }
  30. .bottomList_corner_round_bg {
  31. width: 100%;
  32. height: 80px;
  33. border: 1px solid #000000;
  34. text-align: center;
  35. margin-top: 10px;
  36. margin-left: 10px;
  37. margin-right: 10px;
  38. border-radius: 8px;
  39. divider-color: #000000;
  40. divider-height: 1px;
  41. }
  42. /**
  43. 选中背景
  44. */
  45. .list_corner_round_top {
  46. width: 100%;
  47. height: 80px;
  48. border: 1px solid #000000;
  49. border-top-left-radius: 7px;
  50. border-top-right-radius: 7px;
  51. background: linear-gradient(270deg, #BFEEFF, #40B9FF);
  52. }
  53. .list_corner_round_mid {
  54. width: 100%;
  55. height: 80px;
  56. border: 1px solid #000000;
  57. background: linear-gradient(270deg, #BFEEFF, #40B9FF);
  58. }
  59. .list_corner_round_bottom {
  60. width: 100%;
  61. height: 78px;
  62. border: 1px solid #000000;
  63. border-bottom-left-radius: 7px;
  64. border-bottom-right-radius: 7px;
  65. background: linear-gradient(270deg, #BFEEFF, #40B9FF);
  66. }
  67. .list_corner_round {
  68. width: 100%;
  69. height: 78px;
  70. border: 1px solid #000000;
  71. border-radius: 7px;
  72. background: linear-gradient(270deg, #BFEEFF, #40B9FF);
  73. }
  74. .todo_item_top {
  75. width: 100%;
  76. height: 80px;
  77. border: 1px solid #000000;
  78. border-top-left-radius: 7px;
  79. border-top-right-radius: 7px;
  80. background: linear-gradient(0deg, #FFFFFF, #FFFFFF);
  81. }
  82. .todo_item_mid {
  83. width: 100%;
  84. height: 80px;
  85. border: 1px solid #000000;
  86. background: linear-gradient(0deg, #FFFFFF, #FFFFFF);
  87. }
  88. .todo_item_bottom {
  89. width: 100%;
  90. height: 78px;
  91. border: 1px solid #000000;
  92. border-bottom-left-radius: 7px;
  93. border-bottom-right-radius: 7px;
  94. background: linear-gradient(0deg, #FFFFFF, #FFFFFF);
  95. }
  96. .todo_item_round {
  97. width: 100%;
  98. height: 78px;
  99. border: 1px solid #000000;
  100. border-radius: 7px;
  101. background: linear-gradient(0deg, #FFFFFF, #FFFFFF);
  102. }
  103. .item_title {
  104. font-size: 22px;
  105. text-align: left;
  106. margin-start: 10px;
  107. font-weight: 600;
  108. }
  109. .item_desc {
  110. font-size: 16px;
  111. margin-top: 10px;
  112. color: #77787b;
  113. font-weight: 400;
  114. }
  115. .div_icon {
  116. width: 50px;
  117. height: 100%;
  118. align-items: center;
  119. justify-content: center;
  120. margin-start: 10px;
  121. }
  122. .item_icon {
  123. height: 50px;
  124. width: 100%;
  125. align-items: center;
  126. border-radius: 35px;
  127. background-color: orange;
  128. }
  129. .txt_title {
  130. font-size: 22px;
  131. font-weight: 600;
  132. }
  133. .div_right {
  134. flex-direction: column;
  135. justify-content: center;
  136. }
  137. .div_arrow {
  138. height: 100%;
  139. width: 100%;
  140. margin-end: 10px;
  141. justify-content: center;
  142. align-items: center;
  143. }
  144. .item_arrow {
  145. margin-start: 316;
  146. height: 14px;
  147. width: 14px;
  148. }

Js

  1. import prompt from '@system.prompt';
  2. var timeoutID;
  3. const DURATION = 600;
  4. export default {
  5. data: {
  6. topList: [{
  7. title: 'title3_1',
  8. desc: 'description3_1',
  9. cls: 'todo_item_top',
  10. iconColor: '#99FF0000',
  11. txtColor: 'white',
  12. indexTxt: 'R'
  13. }, {
  14. title: 'title3_2',
  15. desc: 'description3_2',
  16. cls: 'todo_item_mid',
  17. iconColor: '#99FF7D00',
  18. txtColor: 'white',
  19. indexTxt: 'T'
  20. }, {
  21. title: 'title3_3',
  22. desc: 'description3_3',
  23. cls: 'todo_item_bottom',
  24. iconColor: '#99FF00FF',
  25. txtColor: 'white',
  26. indexTxt: 'Y'
  27. }
  28. ],
  29. middleList: [{
  30. title: 'title2_1',
  31. desc: 'description2_1',
  32. cls: 'todo_item_top',
  33. iconColor: '#9900FF00',
  34. txtColor: 'white',
  35. indexTxt: 'U'
  36. }, {
  37. title: 'title2_2',
  38. desc: 'description2_2',
  39. cls: 'todo_item_bottom',
  40. iconColor: '#9900FFFF',
  41. txtColor: 'white',
  42. indexTxt: 'I'
  43. }
  44. ],
  45. bottomList: [{
  46. title: 'title1_1',
  47. desc: 'description1_1',
  48. cls: 'todo_item_round',
  49. iconColor: '#990000FF',
  50. txtColor: 'white',
  51. indexTxt: 'O'
  52. }
  53. ]
  54. },
  55. onTopListItemClick($idx) {
  56. console.info("id = " + $idx);
  57. let index = $idx;
  58. let size = this.topList.length;
  59. if (index == -1) {
  60. for (let i = 0; i < size; i++) {
  61. if (i == 0) {
  62. this.topList[i].cls = "todo_item_top"
  63. } else if (i == size - 1) {
  64. this.topList[i].cls = "todo_item_bottom"
  65. } else {
  66. this.topList[i].cls = "todo_item_mid"
  67. }
  68. }
  69. return;
  70. }
  71. this.onMiddleListItemClick(-1);
  72. this.onBottomListItemClick(-1);
  73. prompt.showToast({
  74. message: this.topList[index].title
  75. });
  76. for (let i = 0; i < size; i++) {
  77. if (index == i) {
  78. if (i == 0) {
  79. this.topList[i].cls = "list_corner_round_top"
  80. } else if (i == size - 1) {
  81. this.topList[i].cls = "list_corner_round_bottom"
  82. } else {
  83. this.topList[i].cls = "list_corner_round_mid"
  84. }
  85. clearTimeout(timeoutID);
  86. timeoutID = setTimeout(this.clearTopItemBg, DURATION);
  87. } else {
  88. if (i == 0) {
  89. this.topList[i].cls = "todo_item_top"
  90. } else if (i == size - 1) {
  91. this.topList[i].cls = "todo_item_bottom"
  92. } else {
  93. this.topList[i].cls = "todo_item_mid"
  94. }
  95. }
  96. }
  97. },
  98. onMiddleListItemClick($idx) {
  99. console.info("id = " + $idx);
  100. let index = $idx;
  101. if (index == -1) {
  102. for (let i = 0; i < 2; i++) {
  103. if (i == 0) {
  104. this.middleList[i].cls = "todo_item_top"
  105. } else {
  106. this.middleList[i].cls = "todo_item_bottom"
  107. }
  108. }
  109. return;
  110. }
  111. this.onTopListItemClick(-1);
  112. this.onBottomListItemClick(-1)
  113. prompt.showToast({
  114. message: this.middleList[index].title
  115. });
  116. for (let i = 0; i < 2; i++) {
  117. if (index == i) {
  118. if (i == 0) {
  119. this.middleList[i].cls = "list_corner_round_top"
  120. } else {
  121. this.middleList[i].cls = "list_corner_round_bottom"
  122. }
  123. clearTimeout(timeoutID);
  124. timeoutID = setTimeout(this.clearMiddleItemBg, DURATION);
  125. } else {
  126. if (i == 0) {
  127. this.middleList[i].cls = "todo_item_top"
  128. } else {
  129. this.middleList[i].cls = "todo_item_bottom"
  130. }
  131. }
  132. }
  133. },
  134. onBottomListItemClick($idx) {
  135. console.info("id = " + $idx);
  136. let index = $idx;
  137. if (index == -1) {
  138. this.bottomList[0].cls = "todo_item_round"
  139. return;
  140. }
  141. this.onTopListItemClick(-1);
  142. this.onMiddleListItemClick(-1);
  143. prompt.showToast({
  144. message: this.bottomList[index].title
  145. });
  146. for (let i = 0; i < 2; i++) {
  147. this.bottomList[0].cls = "list_corner_round"
  148. clearTimeout(timeoutID);
  149. timeoutID = setTimeout(this.clearBottomItemBg, DURATION);
  150. }
  151. },
  152. clearTopItemBg() {
  153. this.onTopListItemClick(-1);
  154. },
  155. clearMiddleItemBg() {
  156. this.onMiddleListItemClick(-1);
  157. },
  158. clearBottomItemBg() {
  159. this.onBottomListItemClick(-1);
  160. }
  161. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/291040
推荐阅读
相关标签