欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序?qū)崿F(xiàn)點(diǎn)擊按鈕移動(dòng)view標(biāo)簽的位置功能示例【附demo源碼下載】

 更新時(shí)間:2017年12月06日 09:59:57   作者:FutrueJet  
這篇文章主要介紹了微信小程序?qū)崿F(xiàn)點(diǎn)擊按鈕移動(dòng)view標(biāo)簽的位置功能,涉及微信小程序事件綁定與this.setData動(dòng)態(tài)修改data數(shù)值進(jìn)而改變view標(biāo)簽樣式的相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了微信小程序?qū)崿F(xiàn)點(diǎn)擊按鈕移動(dòng)view標(biāo)簽的位置功能。分享給大家供大家參考,具體如下:

1、效果展示

2、關(guān)鍵代碼

index.wxml文件

<view class="view" style="left:{{viewLeft}}px;">我是view標(biāo)簽</view>
<button class="btn" type="default" bindtap="changeLocation">點(diǎn)擊我移動(dòng)view標(biāo)簽的位置</button>

index.wxss文件:

.view{
  position: absolute;
  background: green;
  color: white;
  width: 40%;
  height: 50px;
  line-height: 50px;
  text-align: center;
}
.btn{
  position: absolute;
  top:100px;
  width: 80%;
  left: 10%;
}

index.js文件

Page({
  data:{
    viewLeft:0
  },
  changeLocation(){
    var viewLeft=this.data.viewLeft;
    viewLeft+=5;
    this.setData({
      viewLeft:viewLeft
    })
  }
})

可見view組件通過.view的position: absolute;進(jìn)行絕對(duì)位置定位。邏輯層響應(yīng)點(diǎn)擊事件,使用this.setData動(dòng)態(tài)改變style="left:{{viewLeft}}px;"中的viewLeft值,進(jìn)而實(shí)現(xiàn)移動(dòng)view標(biāo)簽的功能。

3、源代碼點(diǎn)擊此處本站下載。

希望本文所述對(duì)大家微信小程序開發(fā)有所幫助。

相關(guān)文章

最新評(píng)論