微信小程序实现banner图轮播(动态获取数据),自动获取图片高度

微信小程序实现banner图轮播(动态获取数据),自动获取图片高度效果图:indicator-active-color=”#007aff”//当前选中的指示点颜色js:constapp=getApp()Page({data:{//———–模拟banner图———–imgUrls:[‘/image/1545118381903.jpg’,’/imag…

大家好,又见面了,我是你们的朋友全栈君。

效果图:

微信小程序实现banner图轮播(动态获取数据),自动获取图片高度

indicator-active-color=”#007aff”//当前选中的指示点颜色 

js:

const app = getApp()

Page({
  data: {
     //-----------模拟banner图-----------
    imgUrls: [
      '/image/1545118381903.jpg',
      '/image/1545118566631.jpg'
    ],
    circular: true,
    //是否显示画板指示点  
    indicatorDots: true,
    //选中点的颜色  
    //是否竖直  
    vertical: false,
    //是否自动切换  
    autoplay: true,
    //自动切换的间隔
    interval: 3000,
    //滑动动画时长毫秒  
    duration: 1000,
    //所有图片的高度  
    imgheights: [],
    //图片宽度 
    imgwidth: 750,
    //默认  
    current: 0
  },
  imageLoad: function (e) {//获取图片真实宽度  
    var imgwidth = e.detail.width,
      imgheight = e.detail.height,
      //宽高比  
      ratio = imgwidth / imgheight;
    console.log(imgwidth, imgheight)
    //计算的高度值  
    var viewHeight = 750 / ratio;
    var imgheight = viewHeight;
    var imgheights = this.data.imgheights;
    //把每一张图片的对应的高度记录到数组里  
    imgheights[e.target.dataset.id] = imgheight;
    this.setData({
      imgheights: imgheights
    })
  },
  bindchange: function (e) {
    // console.log(e.detail.current)
    this.setData({ current: e.detail.current })
  },
   }
})

wxml:

<!-------------首页轮播图-----------------  -->
<view class='swiper'>
  <swiper indicator-dots="{
  
  {indicatorDots}}" vertical="{
  
  {vertical}}" autoplay="{
  
  {autoplay}}" duration="{
  
  {duration}}" interval='{
  
  {interval}}'indicator-active-color="#007aff" bindchange="bindchange" circular="{
  
  {circular}}" style="height:{
  
  {imgheights[current]}}rpx;">
    <block wx:for='{
  
  {imgUrls}}' wx:key="{
  
  {index}}">
      <swiper-item>
        <image src="{
  
  {item}}" data-id='{
  
  {index}}' class="slide-image" mode="widthFix" bindload="imageLoad" />
      </swiper-item>
    </block>
  </swiper>
</view>

wxss:

.swiper image {
  width: 100%;
  height: auto;
}

.swiper-image {
  height: 100%;
  width: 100%;
}

.slide-image {
  height: 100%;
  width: 100%;
  display: block;
}

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/143227.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • jenkinsfile docker_docker从0创建镜像

    jenkinsfile docker_docker从0创建镜像前言之前我们用docker手动安装了jenkins环境,在jenkins中又安装了python3环境和各种安装包,如果我们想要在其他3台机器上安装,又是重复操作,重复劳动,那会显得很low,这里可以

    2022年7月31日
    6
  • html.dropdownlistfor_see的用法

    html.dropdownlistfor_see的用法常用方法后台代码:publicActionResultIndex(){ViewData[“deptOu”]=”SOHO”;using(ISessionsession=newNHibernateHelper(DataBase.ADDB).OpenSession()){IList<t_data_DeptOU>dep…

    2022年10月10日
    2
  • 二进制加减法计算法则

    二进制加减法计算法则一、二进制加法(逢2进1)举例:100111+11010=10000110011111010——————100001十进制加法是逢十进一,二进制加法是逢二进一。最低位:1加0得1。倒数第2位:1加1得2,同时进1。倒数第3位:1加0得1,再加上进位的1,结果为2。其他位同理。二、二进制减法(借1当2)举例:1000001-11010=100111…

    2022年6月24日
    63
  • 内容大合集_十三大内容

    内容大合集_十三大内容文顶顶大神http://www.cnblogs.com/wendingding/p/3805088.html碎片知识大合集http://www.cnblogs.com/wujy/p/457161

    2022年8月5日
    6
  • mysql修改用户密码的方法及命令

    mysql修改用户密码的方法及命令方法1:用SETPASSWORD命令 首先登录MySQL。 格式:mysql&gt;setpasswordfor用户名@localhost=password(‘新密码’); 例子:mysql&gt;setpasswordforroot@localhost=password(‘123456’); 方法2:用mysqladmin 格式:mysqladmin-u用户…

    2022年6月29日
    41
  • 大数据学习之Linux基础[通俗易懂]

    大数据学习之Linux基础[通俗易懂]大数据学习之Linux基础自定义Linux虚拟机安装网络配置1.node1网络配置2.通过快照克隆虚拟机3.配置其他三个节点虚拟机Linux简单命令shell命令运行原理图1.关机与重启2.判断命令的命令3.常用功能命令4.文件系统命令文件系统层次化标准(FileSystemHierarchyStandard)5.文本操作命令vi全屏文本编辑器全屏编辑器模式1.打开文件2.关闭文件3.编辑…

    2022年6月3日
    49

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号