WeChat applet development image drag and drop instance details, program development drag and drop

Source: Internet
Author: User

Detailed description of drag-and-drop instances for applet development, and drag-and-drop for Program Development

Detailed description of drag-and-drop instances for applet Development

1. Compile the Page Structure: moveimg. wxml

<view class="container">   <view class="cnt">     <image class="image-style" src="../uploads/foods.jpg" style="left:{{ballleft}}px;width:{{screenWidth}}px" bindtouchmove="ballMoveEvent">     </image>   </view> </view> 

2. Compile the page style: moveimg. wxss

.container {   box-sizing:border-box;   padding:1rem; } .cnt{   width:100%;   height:15rem;   border: 1px solid #ccc;   position:relative;   overflow: hidden; } .image-style{    position: absolute;    top: 0px;    left:0px;    height:100%;  }  

3. Set Data: moveimg. js

Var app = getApp () Page ({data: {ballleft:-20, screenWidth: 0,}, onLoad: function () {var _ this = this; wx. getSystemInfo ({success: function (res) {_ this. setData ({screenHeight: res. optional wheight, screenWidth: res. required wwidth,}) ;}}) ;}, ballMoveEvent: function (e) {var touchs = e. touches [0]; var pageX = touchs. pageX; console. log ('width' + this. data. screenWidth) console. log ('pagex: '+ pageX); // use right and bottom here. therefore, you need to convert pageX pageY to var x = this. data. screenWidth/2-pageX-20; if (this. data. screenWidth> 385) {if (x> 42) {x = 42 ;}} else {if (x> 32) {x = 32 ;}} if (x <0) {x = 0;} console. log ('x: '+ x) this. setData ({ballleft:-x });}})

I have been studying image cropping over the past few days, but I have encountered various problems. Poor programming is not easy.

After thinking for a long time, let's make a simple start. If you have a better way or other ideas, you are welcome to discuss them together.

Thank you for reading this article. I hope it will help you. Thank you for your support for this site!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.