1. wxml
~~~
<view class="box"bindtouchstart="touchstart"bindtouchmove="touchmove"bindtouchend="touchend">
<view animation="{{animation1}}"bindtap="scrollLeft">
<image src="{{clubs[0]}}"class="img"style="width:{{img_width_one}}rpx"mode='aspectFill'/>
</view>
<view animation="{{animation2}}"bindtap="scrollLeft">
<image src="{{clubs[1]}}"class="img2"/>
</view>
<view animation="{{animation3}}">
<image src="{{clubs[2]}}"class="img3"style="width:{{img_width_three}}rpx"mode='aspectFill'/>
</view>
</view>
~~~
2. js
~~~
Page({
data: {
img_width_three:60,
img_width_one:60,
clubs: [
'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1515151263767&di=7de048755c4fb6136d7937f7d6acc102&imgtype=0&src=http%3A%2F%2Fpic119.nipic.com%2Ffile%2F20161230%2F2168026_223133374033_2.jpg',
'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1515151265766&di=428999ef602db706af795035e93f9ec9&imgtype=0&src=http%3A%2F%2Fpic126.nipic.com%2Ffile%2F20170402%2F4402479_111933865038_2.jpg'
]
},
//觸摸開始事件
touchstart: function (e) {
this.data.touchDot = e.touches[0].pageX;
var that =this;
this.data.interval = setInterval(function () {
that.data.time += 1;
}, 100);
},
//觸摸移動事件
touchmove: function (e) {
let touchMove = e.touches[0].pageX;
let touchDot =this.data.touchDot;
let time =this.data.time;
//向左滑動
if (touchMove - touchDot <= -40 && !this.data.done) {
// console.log("向左滑動");
this.data.done =true;
this.scrollLeft();
}
//向右滑動
if (touchMove - touchDot >=40 && !this.data.done) {
// console.log("向右滑動");
this.data.done =true;
this.scrollRight();
}
},
//觸摸結束事件
touchend: function (e) {
clearInterval(this.data.interval);
this.data.time =0;
this.data.done =false;
},
//向左滑動事件
scrollLeft() {
var animation1 = wx.createAnimation({
duration: 300,
timingFunction: "linear",
delay: 0
})
var animation2 = wx.createAnimation({
duration: 300,
timingFunction: "linear",
delay: 0
})
var animation3 = wx.createAnimation({
duration: 300,
timingFunction: "linear",
delay: 0
})
this.setData({
img_width_three: 200
})
this.animation1 = animation1;
this.animation2 = animation2;
this.animation3 = animation3;
this.animation1.translateX(-60).opacity(0.5).step();
this.animation2.translateX(-60).opacity(1).scale(0.8,0.8).step();
this.animation3.translateX(-60).opacity(0.5).scale(1.2,1.2).step();
this.setData({
animation1: animation1.export(),
animation2: animation2.export(),
animation3: animation3.export(),
})
var that =this;
setTimeout(function () {
that.animation1.translateX(0).opacity(0.5).step({ duration:0, timingFunction:'linear' });
that.animation2.translateX(0).opacity(1).scale(1,1).step({ duration:0, timingFunction:'linear' });
that.animation3.translateX(0).opacity(0.5).scale(1,1).step({ duration:0, timingFunction:'linear' });
that.setData({
animation1: animation1.export(),
animation2: animation2.export(),
animation3: animation3.export(),
img_width_three: 60
})
}.bind(this),300)
let array =this.data.clubs;
let shift = array.shift();
array.push(shift);
setTimeout(function () {
this.setData({
clubs: array
})
}.bind(this),195)
},
//向右滑動事件
scrollRight() {
var animation1 = wx.createAnimation({
duration: 300,
timingFunction: "linear",
delay: 0
})
var animation2 = wx.createAnimation({
duration: 300,
timingFunction: "linear",
delay: 0
})
var animation3 = wx.createAnimation({
duration: 300,
timingFunction: "linear",
delay: 0
})
var animation4 = wx.createAnimation({
duration: 300,
timingFunction: "linear",
delay: 0
})
var animation5 = wx.createAnimation({
duration: 300,
timingFunction: "linear",
delay: 0
})
this.setData({
img_width_one: 200
})
this.animation1 = animation1;
this.animation2 = animation2;
this.animation3 = animation3;
this.animation1.translateX(60).opacity(0.5).scale(1.2,1.2).step();
this.animation2.translateX(60).opacity(1).step();
this.animation3.translateX(60).opacity(0.5).step();
this.setData({
animation1: animation1.export(),
animation2: animation2.export(),
animation3: animation3.export(),
})
var that =this;
setTimeout(function () {
that.animation1.translateX(0).opacity(0.5).scale(1,1).step({ duration:0, timingFunction:'linear' });
that.animation2.translateX(0).opacity(1).scale(1,1).step({ duration:0, timingFunction:'linear' });
that.animation3.translateX(0).opacity(0.5).step({ duration:0, timingFunction:'linear' });
that.setData({
animation1: animation1.export(),
animation2: animation2.export(),
animation3: animation3.export(),
img_width_one: 60
})
}.bind(this),300)
let array =this.data.clubs;
let pop = array.pop();
array.unshift(pop);
setTimeout(function () {
this.setData({
clubs: array
})
}.bind(this),195)
}
})
~~~
3. wxss
~~~
/* pages/prodtype/prodType.wxss */
.box {
z-index:0;
white-space:nowrap;
display:flex;
align-items:center;
justify-content:center;
}
.img {
margin-right:15rpx;
height:520rpx;
}
.img2 {
height:600rpx;
width:600rpx;
}
.img3 {
margin-left:15rpx;
height:520rpx;
}
.box .club:nth-child(1) {
transform:scale(1,1)translateX(0rpx);
opacity:0.2;
z-index:10;
}
.box .club:nth-child(2) {
transform:scale(1,1);
opacity:1;
z-index:100;
}
.box .club:nth-child(3) {
transform:scale(1,1)translateX(0rpx);
opacity:0.2;
z-index:10;
}
~~~
~~~
- 前期準備
- 軟件安裝配置
- 語法 以及 功能 的實現
- 小程序中的 輪播
- 翻轉輪播
- 實現 跳轉 頁面
- 詳談 跳轉頁面
- for 循環 渲染 頁面(重點)
- 點擊 改變 元素內容
- 功能 封裝(創建、使用 模板)(重點)
- js模塊化(重點)
- if-else實現 三目運算
- 底部導航欄tabBar 實現
- 小程序中的 函數調用 方法
- 小程序中的 block 包裹元素
- 小程序中的 hover事件
- import 標簽(重點)
- 其他
- 在本地模擬接口取數據
- 點擊跳轉 并將該元素的id一起傳遞給跳轉的頁面
- 點擊詳情頁顯示
- 點擊事件(bindtap/catchtap)
- 圖片的mode屬性
- 跳轉頁面時實現頂部顯示頁面標題
- hello world
- 將豆瓣服務器接口設置在本地
- 組件
- 地圖
- 下拉刷新
- 數據加載 loading...
- 動態設置導航(title設置)
- 實現js代碼的模塊化
- 傳參
- 組件中的生命周期函數
- 實戰
- 發送http請求
- 可用的豆瓣接口
- 處理豆瓣列表頁的數據
- 從接口上取數據渲染到頁面上1
- 從接口上取數據渲染頁面實現瀑布流2
- 瀑布流
- 音樂播放
- 文章詳情頁
- 音樂播放組件
- 音樂播放 最終版
- 電影(封裝取數據渲染)
- 分享與收藏
- 搜索框
- 將電影列表數據放緩存
- 零碎知識點
- 談組件
- 請求封裝 (重點)
- 實現簡單需求的請求失敗的封裝
- 使用class實現顯示各種錯誤信息
- 再次封裝帶class的請求實現改變里面給的url
- 使用promise 封裝http
- promise
- generator
- 01.介紹
- 02. 基本
- 03. 實例
- 04.yield
- asyns
- 01. 介紹
- 02. 使用
- 03. 取豆瓣
- 子組件(模板文件)接收父組件傳來的參數并改變其值
- 模塊化
- 在模板中提取相同的部分behavior
- 字符串與數組之間的轉換
- 子組件向父組件傳參
- 談 triggerEvent
- 整體展示
- 父組件向子組件傳wxml (在兩個組件比較相似的情況 定義卡 槽傳 wxml)
- 傳css (在父組件中定義子組件的樣式)
- 使用wxs給wxml傳js
- 點贊
- 小程序中的正則
- 組件中實現下拉刷新
- 用戶授權
- 組件點擊圖片獲取信息
- 說明
- 小程序上下滑動