亚洲欧美日韩中文不卡|eeuss电影天堂一区二区|国产美女一级做a爱视频|精品五夜婷香蕉国产线看观看|国产综合另类小说色区色噜噜

小程序 swiper 左右箭頭/前進(jìn)后退/方向控制

行業(yè)動(dòng)態(tài) 公司新聞 案例分享 技術(shù)百科

小程序 swiper 左右箭頭/前進(jìn)后退/方向控制

來(lái)源:奇站網(wǎng)絡(luò ) 瀏覽量:11,179 發(fā)布日期: 2018-03-19

圖片輪播是很經(jīng)常用到的效果,小程度里默認提供了swiper組件,不過(guò)并沒(méi)有左右切換的按鈕/箭頭,這里探討一下如何實(shí)現該功能。

一、靜態(tài)數據

先開(kāi)發(fā)預覽版本,數據全部用的js設定好的本地數據,實(shí)現方式如下:

  1. <view class=swiper-car>
  2. <swiper current={{carIndex}} indicator-dots="{{swiperCar.indicatorDots}}" autoplay="{{swiperCar.autoplay}}" interval="{{swiperCar.interval}}" duration="{{swiperCar.duration}}">
  3. <block wx:for="{{carImgs}}" wx:key="cidx">
  4. <swiper-item>
  5. <image src="{{item}}" class="slide-image" />
  6. </view>
  7. </swiper-item>
  8. </block>
  9. </swiper>
  10. <button class=swiper-left bindtap="bindPrev">
  11. <image src=../../images/swiper-prev.png mode=widthFix></image>
  12. </button>
  13. <button class=swiper-right bindtap="bindNext">
  14. <image src=../../images/swiper-next.png mode=widthFix></image>
  15. </button>
  16. </view>

wxss

  1. .swiper-car {
  2. height: 430rpx;
  3. padding: 0 82rpx;
  4. position: relative;
  5. }
  6. .swiper-car swiper {
  7. height: 450rpx;
  8. }
  9. .swiper-car swiper-item {
  10. font-size: 11pt;
  11. }
  12. .swiper-car swiper-item image {
  13. height: 300rpx;
  14. }
  15. .swiper-car button {
  16. width: 35rpx;
  17. height: 65rpx;
  18. padding: 0;
  19. position: absolute;
  20. top: 50%;
  21. margin-top: -30rpx;
  22. border: 0;
  23. background: transparent;
  24. }
  25. .swiper-car button::after {
  26. border: 0;
  27. }
  28. .swiper-car button image {
  29. width: 35rpx;
  30. }
  31. .swiper-car .swiper-left {
  32. left: 25rpx;
  33. text-align: left;
  34. }
  35. .swiper-car .swiper-right {
  36. right: 25rpx;
  37. }

實(shí)現方式跟網(wǎng)頁(yè)端的輪播類(lèi)似。

二、動(dòng)態(tài)數據

上一個(gè)例子數據是直接在js里給定,很奇怪的是更換成遠程獲取的數據,setData后發(fā)現圖片竟然無(wú)法顯示了,后面發(fā)現是swiper不能在嵌套里的關(guān)系(?),移出view就可以了,但是之前的樣式無(wú)論如何都不起作用了。
剛好swiper上面有個(gè)heading,就將左右箭頭放在heading里,再調整下位置

  1. .heading {
  2. margin-top: 40rpx;
  3. padding: 15rpx;
  4. background: #fff;
  5. font-size: 11pt;
  6. font-weight: bold;
  7. color: #000;
  8. position: relative;
  9. }
  10. .heading .arrow {
  11. width: 30rpx;
  12. height: 59rpx;
  13. z-index: 99;
  14. padding: 80px 20rpx;
  15. }
  16. .heading .swiper-left {
  17. position: absolute;
  18. left: 0;
  19. top: 290rpx;
  20. transform: translate(0, -50%);
  21. cursor: pointer;
  22. }
  23. .heading .swiper-right {
  24. position: absolute;
  25. right: 0;
  26. top: 290rpx;
  27. transform: translate(0, -50%);
  28. }
標簽:

廈門(mén)奇站網(wǎng)絡(luò )科技有限公司

電話(huà):13313868605

QQ:3413772931

地址:廈門(mén)集美區軟件園三期

網(wǎng)站地圖


                    掃一掃加我咨詢(xún)

亚洲欧美日韩中文不卡|eeuss电影天堂一区二区|国产美女一级做a爱视频|精品五夜婷香蕉国产线看观看|国产综合另类小说色区色噜噜