小程序中的事件bindtap,bindchange

movable-area
基础库 1.2.0 开始支持,低版本需做兼容处理。

<movable-view>的可移动区域。

属性	类型	默认值	必填	说明	最低版本
scale-area	Boolean	false	否	当里面的movable-view设置为支持双指缩放时,设置此值可将缩放手势生效区域修改为整个movable-area	1.9.90
Bug & Tip
tip: movable-area 必须设置width和height属性,不设置默认为10px**
tip: 当movable-view小于movable-area时,movable-view的移动范围是在movable-area内;
tip: 当movable-view大于movable-area时,movable-view的移动范围必须包含movable-area(x轴方向和y轴方向分开考虑)
示例代码
在开发者工具中预览效果

<view class="section">
  <view class="section__title">movable-view区域小于movable-area</view>
  <movable-area style="height: 200px; width: 200px; background: red;">
    <movable-view
      style="height: 50px; width: 50px; background: blue;"
      x="{{x}}"
      y="{{y}}"
      direction="all"
    ></movable-view>
  </movable-area>
  <view class="btn-area">
    <button size="mini" bindtap="tap">click me to move to (30px, 30px)</button>
  </view>
  <view class="section__title">movable-view区域大于movable-area</view>
  <movable-area style="height: 100px; width: 100px; background: red;">
    <movable-view
      style="height: 200px; width: 200px; background: blue;"
      direction="all"
    ></movable-view>
  </movable-area>
  <view class="section__title">可放缩</view>
  <movable-area
    style="height: 200px; width: 200px; background: red;"
    scale-area
  >
    <movable-view
      style="height: 50px; width: 50px; background: blue;"
      direction="all"
      bindchange="onChange"
      bindscale="onScale"
      scale
      scale-min="0.5"
      scale-max="4"
      scale-value="2"
    ></movable-view>
  </movable-area>
</view>
Page({
  data: {
    x: 0,
    y: 0
  },
  tap(e) {
    this.setData({
      x: 30,
      y: 30
    })
  },
  onChange(e) {
    console.log(e.detail)
  },
  onScale(e) {
    console.log(e.detail)
  }
})

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
当然,我很乐意为您提供微信小程序更多的API和组件用法及案例代码。以下是我为您准备的微信小程序20个API和组件用法及案例代码: 1. wx.getUserInfo() - 获取用户信息 ``` wx.getUserInfo({ success: function(res) { var userInfo = res.userInfo; var nickName = userInfo.nickName; console.log(nickName); } }) ``` 2. wx.showActionSheet() - 显示操作菜单 ``` wx.showActionSheet({ itemList: ['item1', 'item2', 'item3'], success: function(res) { console.log(res.tapIndex); } }) ``` 3. wx.chooseImage() - 选择图片 ``` wx.chooseImage({ count: 1, sizeType: ['original', 'compressed'], sourceType: ['album', 'camera'], success: function(res) { var tempFilePaths = res.tempFilePaths; console.log(tempFilePaths); } }) ``` 4. wx.getLocation() - 获取地理位置 ``` wx.getLocation({ type: 'wgs84', success: function(res) { var latitude = res.latitude; var longitude = res.longitude; console.log(latitude, longitude); } }) ``` 5. wx.openLocation() - 打开地图 ``` wx.openLocation({ latitude: 23.10229, longitude: 113.3345211, scale: 28, name: 'name', address: 'address' }) ``` 6. wx.getSystemInfo() - 获取系统信息 ``` wx.getSystemInfo({ success: function(res) { var system = res.system; console.log(system); } }) ``` 7. wx.navigateToMiniProgram() - 打开其他小程序 ``` wx.navigateToMiniProgram({ appId: 'appId', path: 'path', extraData: { key: 'value' }, envVersion: 'develop/release', success(res) {} }) ``` 8. wx.createInnerAudioContext() - 创建音频实例 ``` var audioCtx = wx.createInnerAudioContext(); audioCtx.src = 'audio.mp3'; audioCtx.play(); ``` 9. wx.chooseVideo() - 选择视频 ``` wx.chooseVideo({ sourceType: ['album', 'camera'], maxDuration: 60, camera: 'back', success: function(res) { var tempFilePath = res.tempFilePath; console.log(tempFilePath); } }) ``` 10. wx.createVideoContext() - 创建视频上下文 ``` var videoCtx = wx.createVideoContext('video'); videoCtx.play(); ``` 11. wx.createInterstitialAd() - 创建插屏广告实例 ``` var interstitialAd = wx.createInterstitialAd({ adUnitId: 'adUnitId' }) interstitialAd.show(); ``` 12. wx.createRewardedVideoAd() - 创建激励视频实例 ``` var rewardedVideoAd = wx.createRewardedVideoAd({ adUnitId: 'adUnitId' }) rewardedVideoAd.show(); ``` 13. <view> - 视图容器组件 ``` <view class="container"> <text>Hello, world!</text> </view> ``` 14. <text> - 文本组件 ``` <text class="text">Hello, world!</text> ``` 15. <button> - 按钮组件 ``` <button class="button" bindtap="onButtonClick">Click me</button> ``` 16. <input> - 输入框组件 ``` <input class="input" type="text" placeholder="Input something..." bindinput="onInput" /> ``` 17. <image> - 图片组件 ``` <image class="image" src="image.png" mode="aspectFit" /> ``` 18. <swiper> - 滑块视图容器组件 ``` <swiper class="swiper" autoplay="true" interval="5000"> <swiper-item> <image src="image1.png" /> </swiper-item> <swiper-item> <image src="image2.png" /> </swiper-item> </swiper> ``` 19. <scroll-view> - 可滚动视图容器组件 ``` <scroll-view class="scroll-view" scroll-x="true"> <view class="item">item1</view> <view class="item">item2</view> <view class="item">item3</view> </scroll-view> ``` 20. <picker> - 选择器组件 ``` <picker class="picker" mode="date" bindchange="onPickerChange"> <view class="picker-text">{{pickerValue}}</view> </picker> ``` 以上是我为您准备的微信小程序20个API和组件用法及案例代码,希望对您有所帮助。如果您需要更多的API和组件用法及案例代码,可以查看官方文档。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值