找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索本站精品资源

首页 教程频道 小程序开发 查看内容

幻灯片,tab导航切换

作者:模板之家 2018-1-25 11:40 7602人关注

使用微信小程序原生组件swiper实现。 swiper indicator-dots={{indicatorDots}} autoplay={{autoplay}} interval={{interval}} duration={{duration}} block wx:for={{imgUrls}} wx:key=index swiper-item image src ...

  • 使用微信小程序原生组件swiper实现。


  1. <swiper 
  2.         indicator-dots="{{indicatorDots}}" 
  3.         autoplay="{{autoplay}}" 
  4.         interval="{{interval}}" 
  5.         duration="{{duration}}">
  6.         <block wx:for="{{imgUrls}}" wx:key="index">
  7.             <swiper-item>
  8.                 <image src="{{item}}" class="slide-image" 
  9.                 mode="scaleToFill"/>
  10.             </swiper-item>
  11.         </block>
  12.     </swiper>

配合在逻辑页面配置数据实现幻灯片

  1. Page({
  2.         data: {
  3.             imgUrls: [],
  4.             indicatorDots: true,
  5.             autoplay: true,
  6.             interval: 2000,
  7.             duration: 1000,
  8.         },
  9.         onLoad: function(){
  10.             util.ajax({
  11.                 url: 'https://api.zg5v.com/index.php/index/show/banner',
  12.                 data: {
  13.                     uid: 194
  14.                 },
  15.                 cb: function(res) {
  16.                     setSilde.call(self, res.data.data);
  17.                 }
  18.             });
  19.         }
  20.     })
tab导航切换
  • 由于微信小程序不能直接操作DOM,所以这里设置一个data-id值。(data-id="{{index}}" )用来模拟DOM操作,来实现导航内容的切换


  1. <view class="nav-warp">
  2.         <view class="tab">
  3.             <block wx:for="{{navItem}}" wx:key="index">
  4.                 <text bindtap="navToggle" 
  5.                     data-id="{{index}}" 
  6.                     class="tab-txt 
  7.                             {{showItem == index ? 'active' : '' }}">
  8.                     {{item}}
  9.                 </text>
  10.             </block>
  11.         </view>
  12.     </view>

用于模拟DOM操作

  1. Page({
  2.         data: {
  3.             showItem: 0
  4.         },
  5.         navToggle: function(e){
  6.             this.setData({
  7.                 showItem: e.target.dataset.id    
  8.             });
  9.             util.dataList.call(this, {
  10.                 url: 'https://api.zg5v.com/index.php/index/show/qtshow',
  11.                 data: {
  12.                     uid: 148,
  13.                     fenid: e.target.dataset.id - 1,
  14.                     num: 0
  15.                 },
  16.                 cb: util.petAge
  17.             });
  18.         }   
  19.     });


路过

雷人

握手

鲜花

鸡蛋
原作者: 模板之家 来自: 网络收集

全部回复(0)