weex icon indicating copy to clipboard operation
weex copied to clipboard

关于 slider 组件的 index

Open lmnsg opened this issue 10 years ago • 5 comments

虽然文档上没有写,但是我测试中发现是可以通过为 slider 添加属性 index=number 的方式来控制 slider 的 index 的,但是发现了一个 bug,就是在 ios 中,当 slider 里的内容超过 2个的时候此方式有效,当小于等于2的时候就不行了。

是什么问题呢...

lmnsg avatar Oct 21 '16 03:10 lmnsg

试了下,在data里设置index属性是可以的,下面是我测试的代码

<template>
  <div>
    <slider style="width:{{sliderwidth}};padding-bottom:24;" auto-play='true' interval=2000 onchange="sliderChange">
      <div repeat={{divlist}}>
        <div style="flex-direction:row;margin-top:24;">
          <text style="margin-left:24;margin-top:12;width:{{textwidth}}">{{title}}</text>
          <switch checked="true" onchange="changeSwitch" style="margin-left:10;"></switch>
        </div>
        <image style="width:100;height:80;margin-top:24;margin-left:24;" src="{{pictureUrl}}"></image>
      </div>
      <indicator style="width:{{sliderwidth}};height:380;top:20;position:absolute;item-size:12;item-color:red;item-selectedColor:blue;">
      </indicator>
    </slider>

    <video style="width:{{sliderwidth}};height:380;margin-top:24;" src="http://static.tripbe.com/videofiles/20121214/9533522808.f4v.mp4" auto-play='true'>
    </video>

    <a style="margin:24;" href="http://127.0.0.1:3500/examples/gesture/gesture-demo.js">
      <text>Click me to see how 'A' element opens a new world.</text>
    </a>

  </div>
</template>

<script>
  module.exports = {
    data: {
      divlist: [
                {'title':'Hello world Jack','index':0, 'pictureUrl':'http://t.cn/RGE3uo9'},
                {'title':'Great day!','index':1,'pictureUrl':'http://t.cn/RGE31hq'},
                // {'title':'Your name','index':2,'pictureUrl':'http://t.cn/RGE3AJt'}
              ],
      sliderwidth: 750,
      textwidth: 602
    },
    methods: {
      changeSwitch: function(e) {
        console.log(JSON.stringify(e))
      },
      sliderChange: function(e) {
        console.log('slider index is '+JSON.stringify(e.index))
      }
    }
  };
</script>

zzyhappyzzy avatar Nov 21 '16 01:11 zzyhappyzzy

突然发现在手机上slider能够自适应高度,为什么浏览器必须设置高度才能显示出来。。。 上面的例子,如果在浏览器调试,需要在slider的style新增height属性,如:

style="width:{{sliderwidth}};padding-bottom:24;height:220;"

zzyhappyzzy avatar Nov 21 '16 02:11 zzyhappyzzy

@zzyhappyzzy 你的例子里我没看到有设置 index 啊

lmnsg avatar Nov 21 '16 10:11 lmnsg

又看了下源码,估计是我理解错了。 如果通过index属性指定slider默认的位置,小于2个时确实有问题

zzyhappyzzy avatar Nov 21 '16 11:11 zzyhappyzzy

@zzyhappyzzy 是这样的

lmnsg avatar Nov 22 '16 01:11 lmnsg