相信大家在平常购物的时候都会看到轮播图,轮播图里面播放的是热门商品的信息。在小程序里面我们可以通过swiper滑动视图容器组件来实现,让我们一起来看下swiper组件都有哪些属性:

我们看到可以通过一些属性给视图容器增加一些指示点,这些指示点代表了这些滑块在容器中的位置。我们也可以设置指示点的颜色或者对当前选中的指示点设置颜色,同时我们也可以通过autoplay这个属性来设置自动播放轮播图。现在让我们通过一个实例来看下吧:

从图中我们可以看到,通过<button>组件我们可以设置轮播图的一些功能:

<!--index.wxml-->

<view>swiper组件</view>

<view class="section">

<view class="page-body">

<view class="page-section page-section-spacing swiper">

<swiper

indicator-dots="{{indicatorDots}}"

autoplay="{{autoplay}}"

interval="{{interval}}"

duration="{{duration}}"

bindchange="change"

bindanimationfinish="animationfinish"

>

<block wx:for="{{background}}" wx:key="*this">

<swiper-item>

<view class="swiper-item {{item}}"></view>

</swiper-item>

</block>

</swiper>

</view>

<view class="page-section" style="margin-top: 40rpx;margin-bottom: 0;">

<view class="weui-cells weui-cells_after-title">

<view class="weui-cell weui-cell_switch">

<view class="weui-cell__bd">指示点</view>

<view class="weui-cell__ft">

<switch checked="{{indicatorDots}}" bindchange="changeIndicatorDots" />

</view>

</view>

<view class="weui-cell weui-cell_switch">

<view class="weui-cell__bd">自动播放</view>

<view class="weui-cell__ft">

<switch checked="{{autoplay}}" bindchange="changeAutoplay" />

</view>

</view>

</view>

</view>

<view class="page-section page-section-spacing">

<view class="page-section-title">

<text>幻灯片切换时长(ms)</text>

<text class="info">{{duration}}</text>

</view>

<slider bindchange="durationChange" value="{{duration}}" min="500" max="2000" />

<view class="page-section-title">

<text>自动播放间隔时长(ms)</text>

<text class="info">{{interval}}</text>

</view>

<slider bindchange="intervalChange" value="{{interval}}" min="2000" max="10000" />

</view>

</view>

</view>

/*index.wxss*/

button {

margin-bottom: 30rpx;

}

button:last-child {

margin-bottom: 0;

}

.page-body {

width: 100%;

}

.page-section-title {

padding: 0;

}

.swiper-item {

display: block;

height: 150px;

}

.page-section-title {

margin-top: 60rpx;

position: relative;

}

.info {

position: absolute;

right: 0;

color: #353535;

font-size: 30rpx;

}

.page-foot {

margin-top: 50rpx;

}

.demo-text-1 {

position: relative;

align-items: center; /*居中对齐各项demo-text-1元素*/

justify-content: center; /*居中排列,周围留有空白*/

background-color: #1AAD19;

color: #FFFFFF;

font-size: 36rpx;

}

.demo-text-1:before { /*向demo-text-1元素前加入*/

content: 'A';

position: absolute;

top: 50%;

left: 50%;

transform: translate(-50%, -50%);

}

.demo-text-2 {

position: relative;

align-items: center;

justify-content: center;

background-color: #2782D7;

color: #FFFFFF;

font-size: 36rpx;

}

.demo-text-2:before {

content: 'B';

position: absolute;

top: 50%;

left: 50%;

transform: translate(-50%, -50%); /*旋转元素*/

}

.demo-text-3 {

position: relative;

align-items: center;

justify-content: center;

background-color: #F1F1F1;

color: #353535;

font-size: 36rpx;

}

.demo-text-3:before {

content: 'C';

position: absolute;

top: 50%;

left: 50%;

transform: translate(-50%, -50%);

}

//index.js

Page({

data: {

background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],

indicatorDots: true,

vertical: false,

autoplay: false,

interval: 2000,

duration: 300

},

changeIndicatorDots: function (e) {

console.log('切换指示点开关');

this.setData({

indicatorDots: !this.data.indicatorDots /*!在Javascript中是取反的意思*/

})

},

changeAutoplay: function (e) {

console.log('切换自动播放开关');

this.setData({

autoplay: !this.data.autoplay

})

},

intervalChange: function (e) {

console.log(`调整自动播放间隔时长为: ${e.detail.value}ms`);

this.setData({

interval: e.detail.value /*取值*/

})

},

durationChange: function (e) {

console.log(`调整幻灯片切换时长为: ${e.detail.value}ms`);

this.setData({

duration: e.detail.value

})

},

animationfinish: function(e) {

console.log(e);

},

change: function(e) {

console.log(e);

}

})

今天的内容就到这里了,我们明天见。

swiper鼠标hover停止自动轮播_swiper滑块组件相关推荐

  1. 原生JS制作自动+手动轮播图,附带二级分类菜单

    原生JS制作自动+手动轮播图,附带二级分类菜单 包含以下功能: 1.鼠标移开自动轮播 2.鼠标移入停止自动轮播 3.点击左右按钮可手动切换图片 4.点击索引小圆点可手动切换图片 5.鼠标移入一级菜单展 ...

  2. ViewPager自动轮播,手指按住停止轮播

    前面写了ViewPager添加指示器,无限轮播,自动轮播.但是自动轮播有一个问题就是手指按住后要停止轮播才行. 添加指示器,无限轮播,自动轮播请参考另外两篇文章: <viewpager自添加指示 ...

  3. 横向自动轮播图html代码,JavaScript实现PC端横向轮播图

    JavaScript实现PC端横向轮播图 发布时间:2020-09-09 02:10:03 来源:脚本之家 阅读:100 作者:菜鸟向往蓝天 本文实例为大家分享了JavaScript实现PC端横向轮播 ...

  4. 【jQuery案例】 自动轮播图

    [jQuery案例] 自动轮播图 使用jQuery实现了图片自动轮播 有左右按钮和底部小圆点选择功能 源代码如下: <!DOCTYPE html> <html lang=" ...

  5. JS完成轮播图(全部JS代码,自动轮播)

    需求: 1.点击左右方向图标切换图片 2.点击图片中的小圆点切换对应图片 3.切换图片改变对应小圆点的颜色 4.鼠标离开时自动轮播,鼠标滑入停止轮播 5.不能有空白 思路: 1.先布局,创建轮播图显示 ...

  6. 手把手带你用viewpager实现gallary效果,外加无限循环,自动轮播

    手把手带你用viewpager实现gallary效果,外加无限循环,自动轮播 效果图:图很丑,各位看官且按需更改. 主要功能: ①Gallary样式 ②无限轮播 ③自动轮播和手势操作间冲突解决 提前说 ...

  7. 打造一个丝滑般自动轮播无限循环Android库

    作者:一包纯牛奶 链接: https://juejin.im/post/5d6bce24f265da03db0790d1 本文由作者授权发布. 这里我把作者两篇文章合体了,主要是为了在项目功能介绍的基 ...

  8. swiper移入暂停_react中swiper注意事项及鼠标划入停止轮播

    首先是实例化swiper 这里有一个注意点,就是实例化的时机 如果你的swiper内容是写死的,可以在componentDidMount中实例化,但是如果你的内容是通过接口异步请求过来的,就必须在co ...

  9. swiper轮播器的常用案例分析(swiper hover停止mouseover停止)

    API地址 基础演示 hover停止需要自己设置,代码如下 var mySwiper= new Swiper('.swiper-container', {//这里的常规的设置参数pagination: ...

最新文章

  1. javaScript的调试(二)
  2. 【python图像处理】彩色映射(续篇)
  3. python 进位_Python小课堂(第一讲)
  4. 文本分类(一)EWECT微博情绪分类大赛第三名Bert-Last_3embedding_concat最优单模型复现
  5. three 天空球_javascript – 分配给相机的three.js天空盒
  6. easyPR源码解析之chars_identify.h
  7. eclipse下开发简单的Java Web Service
  8. 安装php的mongodb扩展
  9. 人脸重建速览,从3DMM到表情驱动动画
  10. [pion]写一个简单的turn服务器
  11. 华为交换机各种配置实例
  12. 今日头条推荐算法原理
  13. springcloud Netflix
  14. 如何使用SIGFOX技术连接物联网?
  15. Perl面向对象编程入门
  16. 【歌曲分享-第一期】Bendy and the Ink Machine
  17. Orz_panda cup I题 (xdoj1117) 状压dp
  18. ——大牛很通俗地介绍《信号与系统》
  19. win10重装系统打开分区或者磁盘提示无法访问解决办法
  20. nodeJS实现简易爬虫

热门文章

  1. java 获取oracle表结构_获取Oracle中所有表的列表?
  2. Windows平台RTSP|RTMP播放端SDK集成说明
  3. ajax提交加载loading图标遮罩层不显示
  4. mybatis笔记之一次插入多条数据sql语句写法
  5. linux 为什么要安装gcc和gcc-c++(又叫做g++)
  6. 计算机学业水平考试答题卡,高一年级期末信息技术考试(含答题卡)
  7. 计算机桌面打标签,在电脑桌面上添加便签的方法步骤详解(2)
  8. 两个摄像头合成一路_教你把一个摄像机添加到两台录像机
  9. treegrid 如何获取getchanges inserted_如何避开Vue性能优化之路的荆棘?
  10. oracle如何收缩表空间,ORACLE收缩表空间