• 小程序slider实现双向滑动(价格区间选择)

    1. wxml 代码:

    2. <view class='sliderView'>

    3. <slider class='left' block-color='orange'  bindchange="leftSchange" min='{{leftMin}}' max='{{leftMax}}' value='{{leftValue}}' activeColor='rgb(243,242,247)' backgroundColor='rgb(243,242,247)' block-size='14'/>

    4. <slider class='right' block-color='orange' bindchange="rightSchange" min='{{rightMin}}' max='{{rightMax}}' value='{{rightValue}}' activeColor='rgb(243,242,247)' backgroundColor='rgb(243,242,247)' block-size='14'/>

    5. </view>

    6. wxss 代码:

    7. .sliderView{

    8. position: relative;

    9. width: 93%;

    10. margin: 0 15rpx

    11. }

    12. .left{

    13. position: absolute;

    14. width: 90%

    15. }

    16. .right{

    17. position: absolute;

    18. width: 90%

    19. }

    20. js 代码:

    21. data: {

    22. leftMin: 0,

    23. leftMax: 6,

    24. rightMin: 0,

    25. rightMax: 6,

    26. leftValue: 0,

    27. rightValue: 6

    28. },

    29. //价格slider滑动

    30. leftSchange: function (e) {

    31. var that = this

    32. that.setData({

    33. isQuery: false

    34. })

    35. var value = e.detail.value

    36. if(value==that.data.rightValue){

    37. if(that.data.rightValue==6) value--

    38. else value++

    39. }

    40. that.setData({

    41. leftValue: value

    42. })

    43. if(value<that.data.rightValue){

    44. var bg_price = that.data.priceList[value].slice(1)

    45. var end_price = that.data.priceList[that.data.rightValue].slice(1)

    46. }

    47. else{

    48. var end_price = that.data.priceList[value].slice(1)

    49. var bg_price = that.data.priceList[that.data.rightValue].slice(1)

    50. }

    51. list['bg_price'] = bg_price

    52. list['end_price'] = end_price

    53. wx.setStorageSync("priceList", { bg_price: value, end_price: that.data.leftValue})

    54. setTimeout(function () {

    55. wxb.Post('/api/minsu.index/index', list, function (data) {

    56. console.log(list,"价格slider")

    57. console.log(data)

    58. that.setData({

    59. isQuery: true

    60. })

    61. if (data.length != 0) {

    62. that.setData({

    63. result: data.num + '套',

    64. })

    65. }

    66. else {

    67. that.setData({

    68. result: '0套',

    69. })

    70. }

    71. })

    72. }, 700)

    73. },

    74. //右边

    75. rightSchange: function (e) {

    76. var that = this

    77. that.setData({

    78. isQuery: false

    79. })

    80. var value = e.detail.value

    81. if (value == that.data.leftValue) {

    82. if(that.data.leftValue==6) value--

    83. else value++

    84. }

    85. that.setData({

    86. rightValue: value

    87. })

    88. if (value < that.data.leftValue) {

    89. var bg_price = that.data.priceList[value].slice(1)

    90. var end_price = that.data.priceList[that.data.leftValue].slice(1)

    91. }

    92. else {

    93. var end_price = that.data.priceList[value].slice(1)

    94. var bg_price = that.data.priceList[that.data.leftValue].slice(1)

    95. }

    96. list['bg_price'] = bg_price

    97. list['end_price'] = end_price

    98. wx.setStorageSync("priceList", { bg_price: value, end_price: that.data.leftValue })

    99. setTimeout(function () {

    100. wxb.Post('/api/minsu.index/index', list, function (data) {

    101. console.log(list, "价格slider")

    102. console.log(data)

    103. that.setData({

    104. isQuery: true

    105. })

    106. if (data.length != 0) {

    107. that.setData({

    108. result: data.num + '套',

    109. })

    110. }

    111. else {

    112. that.setData({

    113. result: '0套',

    114. })

    115. }

    116. })

    117. }, 700)

    118. },

    119. 20180905134316802.png

    120. 转自https://blog.csdn.net/zhanjinfeng/article/details/82422444