zoukankan      html  css  js  c++  java
  • 小程序笔记三:幻灯片swiper 和图片自定义高度

    滑动组件:scroll-view

    wxml代码

    <view>
     <scroll-view scroll-x="true" class="tab-h" scroll-left="{{scrollLeft}}">
            <view class="tab-item {{currentTab==0?'active':''}}"  data-current="0" bindtap="swichNav">健康</view>
            <view class="tab-item {{currentTab==1?'active':''}}" data-current="1" bindtap="swichNav">情感</view>
            <view class="tab-item {{currentTab==2?'active':''}}" data-current="2" bindtap="swichNav">职场</view>
            <view class="tab-item {{currentTab==3?'active':''}}" data-current="3" bindtap="swichNav">育儿</view>
            <view class="tab-item {{currentTab==4?'active':''}}" data-current="4" bindtap="swichNav">纠纷</view>
            <view class="tab-item {{currentTab==5?'active':''}}" data-current="5" bindtap="swichNav">青葱</view>
            <view class="tab-item {{currentTab==6?'active':''}}" data-current="6" bindtap="swichNav">全部</view>
            <view class="tab-item {{currentTab==7?'active':''}}" data-current="7" bindtap="swichNav">其他</view>
        </scroll-view>
    </view>

    js代码

    page({
       data:{
               currentTab:0
         } 
    })    

    wxss代码

    .tab-h{height: 80rpx; 100%; box-sizing: border-box;overflow: hidden;line-height: 80rpx;background: #F7F7F7; font-size: 16px; white-space: nowrap;position: relative;top: 0; left: 0; z-index: 99;}
    .tab-item{margin:0 36rpx;display: inline-block;}
    .tab-item.active{color: #4675F9;position: relative;}
    .tab-item.active:after{ content: "";display: block;height: 8rpx; 52rpx;background: #4675F9;position: absolute; bottom: 0;left: 5rpx;border-radius: 16rpx;}

     参考地址:https://blog.csdn.net/sophie_u/article/details/71745125

    幻灯片组件:swiper

    js代码:

    Page({
      data: {
        imgUrls: [
          'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
          'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
          'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
        ],
        indicatorDots: false,
        autoplay: false,
        interval: 5000,
        duration: 1000
      },
      
    })
    

      

    wxml代码

    <swiper indicator-dots="{{indicatorDots}}"
      autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}">
      <block wx:for="{{imgUrls}}">
        <swiper-item>
          <image src="{{item}}" class="slide-image" width="355" height="150"/>
        </swiper-item>
      </block>
    </swiper>
    

      

    参考手册:https://mp.weixin.qq.com/debug/wxadoc/dev/component/scroll-view.html

    图片自定义高度

    图片实际imgW:1080px   imgH:300px;

    小程序屏幕宽度750

    小程序图片高度 = 750/(1080/300)

    // 如
    <swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" bindchange="bindchange" style="height:{{750/(vo.floor_swiper[0].imgW/vo.floor_swiper[0].imgH)}}rpx;" data-d="{{v.img_height}}">

    小程序图片高度设定

    方法一:在后台直接填写参数(推荐使用)

    方法二:小程序js计算

  • 相关阅读:
    git 命令行下浏览器tig使用记录
    根据进程名字杀死进程
    centos7 在线安装postgresql9.5
    HttpClient使用代理访问
    nmap查看服务器端口使用情况
    java后台启动jar包
    不同语言,系统通过共享内存方式实现信息交互
    释放 MappedByteBuffer映射的内存
    Java使用ByteBuffer读取大文件
    Java共享内存
  • 原文地址:https://www.cnblogs.com/wesky/p/8417841.html
Copyright © 2011-2022 走看看