微信小程序swiper滑动-仿饿了么

古城微笑少年丶 2021-07-25 01:50 615阅读 0赞

前言:本篇swiper滑动可以根据需要一页显示多少项内容(根据数组渲染的)。除外,还能修改指示点的默认和选中的样式。


饿了么-gif效果图片:
在这里插入图片描述


示例-gif效果图片:
在这里插入图片描述


wxml:

  1. <view>
  2. <!-- swiper实例 -->
  3. <view>
  4. <swiper class="swiper-box" style="height: 280rpx;border: 1px solid red;" indicator-dots="{ { indicatorDots2}}" circular="{ { circular2}}" interval="{ { interval2}}" duration="{ { duration2}}"> <!-- 一级循环 --> <black wx:for="{ { list}}" wx:key="index">
  5. <swiper-item style="display: flex;align-items: center;border: 1px solid blue;flex-wrap: wrap;"> <!-- 二级循环 --> <block wx:for="{ { item}}" wx:key="index" wx:for-item="items">
  6. <view style="width: 25%;text-align: center;height: 100rpx;"> <view>{ { items.name}}</view>
  7. </view>
  8. </block>
  9. </swiper-item>
  10. </black>
  11. </swiper>
  12. </view>
  13. </view>

wxss:

  1. /* pages/swipers/swiper.wxss */
  2. /* 默认指示点的样式 */
  3. .swiper-box .wx-swiper-dot {
  4. width: 16rpx;
  5. height: 4rpx;
  6. border-radius: 0;
  7. background: rgb(178, 178, 178);
  8. }
  9. /* 选中指示点的样式 */
  10. .swiper-box .wx-swiper-dot.wx-swiper-dot-active {
  11. width: 24rpx;
  12. height: 4rpx;
  13. background: rgb(23, 174, 230);
  14. }

js:

  1. // pages/swipers/swiper.js Page({
  2. /** * 页面的初始数据 */
  3. data: {
  4. indicatorDots2: true, circular2: false, interval2: 2000, duration2: 500, list: [ [{
  5. id: 1,
  6. name: "苹果"
  7. },
  8. {
  9. id: 2,
  10. name: "沙果"
  11. },
  12. {
  13. id: 3,
  14. name: "海棠"
  15. },
  16. {
  17. id: 4,
  18. name: "野樱莓"
  19. },
  20. {
  21. id: 5,
  22. name: "枇杷"
  23. },
  24. {
  25. id: 6,
  26. name: "野樱莓11"
  27. },
  28. {
  29. id: 7,
  30. name: "枇杷11"
  31. }
  32. ], [{
  33. id: 1,
  34. name: "欧楂"
  35. },
  36. {
  37. id: 2,
  38. name: "山楂"
  39. },
  40. {
  41. id: 3,
  42. name: "雪梨"
  43. },
  44. {
  45. id: 4,
  46. name: "温柏"
  47. },
  48. {
  49. id: 5,
  50. name: "蔷薇果"
  51. }
  52. ], [{
  53. id: 1,
  54. name: "花楸"
  55. },
  56. {
  57. id: 2,
  58. name: "樱桃"
  59. },
  60. {
  61. id: 3,
  62. name: "油桃"
  63. },
  64. {
  65. id: 4,
  66. name: "李子"
  67. },
  68. {
  69. id: 5,
  70. name: "白玉樱桃"
  71. }
  72. ]
  73. ]
  74. },
  75. /** * 生命周期函数--监听页面加载 */
  76. onLoad: function(options) {
  77. console.log(this.data.list)
  78. }
  79. })

发表评论

表情:
评论列表 (有 0 条评论,615人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Android仿饿购物车功能

    现在商城应用上,购物车功能可以说是不可缺少的,每个应用的购物车模块实现方式都差不多,这篇我们来仿一下饿了么的购物车功能,用过的童鞋都知道,印象最深刻的应该是添加或减少数量时,抛