How to use the CSS Transition property to implement the micro-message applet parts that drive the picture to be hidden

Source: Internet
Author: User
This article mainly introduces the use of CSS transition properties to achieve a drive to draw the hidden parts of the relevant data, the need for friends can refer to the following

Let's see first.

A small part with transition effect in our actual development of the application probability is still relatively large, However, in the process of developing the small program may have a small partner found transition this property it does not work (described below) so we will consider to use the official Wx.createanimation API to create the animation.

Next, I'll take you guys. How to make the transition attribute work in this requirement, the code below

Page ({    data: {        show:false//used to show or hide    the control},    chanmask:function () {        var isshow = This.data.show? false : true;//If display is hidden, hide to show        this.setdata ({            show:isshow        })    })

/*index.wxss*//* show the former */.mask-con{transition:1s; Position:fixed;width:100%;height:300rpx;left:0;bottom: -300rpx; text-align:center;line-height:300rpx;box-shadow:0 1px 10px #aaa;} /* display after */.mask-con-show{bottom:0;} <!--index.wxml--><view class= "container" ><button bindtap= "Chanmask" > Point me </button><view Class= "Mask-con {show? ' Mask-con-show ': '} ' ><view class= "close" bindtap= "Chanmask" >X</view> slowly fly </view></view >

In the above code we first define a show variable for the display state of the Mask-con control in data, alternately change the variable in the Chanmask function, and then bind the Chanmask function to the Click event of the button and the close control. Finally, we decide whether to add a class:mask-con-show to Mask-con (our animation control) based on show so here we have implemented a hidden widget with transitions, but for some requirements this is too reluctant, for example:

Now a lot of apps or small programs are in this way to close the pop-up window control, the X-user point of addiction, see here Smart small partners may think of adding another shadow control in the lower layer of Mask-con and bind our chanmask function, In this case, the shadow control and our Mask-con may not be in a whole, not intuitive, and for example, the leader to let this shadow it has a display color slowly deepened, hiding the effect of slow fade, in order to deal with this situation, we will adjust the code as follows:

Page ({    data: {        show:false//is used to show or hide    The Mask control},    chanmask:function () {        var isshow = this.data.show? false:true;//If the display is hidden,        this.setdata ({            show:isshow        })    }) is hidden/*index.wxss*/.mask-shadow{width: 100%;height:100%; Opacity:0;transition:1s;}. mask-shadow-on{opacity:0.3;}. Mask-con{position:absolute;width:100%;height:300rpx;left:0;bottom: -300rpx; transition:1s;text-align:center; line-height:300rpx;box-shadow:0 1px 10px #aaa;}. mask-con-show{bottom:0;} <!--index.wxml--><view class= "container" ><button bindtap= "Chanmask" > Point I </button><view class= "Mask {{show?} ' Show ': ' Hide '} ' ><view class= ' Mask-shadow {show? ' Mask-shadow-on ': '}} ' ></view><view class= ' Mask-con {show? ' Mask-con-show ': '} ' ><view class= "close" bindtap= "Chanmask" >X</view> slowly fly </view></view ></view>

Here we set up two style class names mask-shadow-on and mask-con-show to define the effect of the shadow as well as the main control Mask-con the animation (depending on your needs), everything looks OK, no problem, then run first wave, Emma, God horse situation? The shadow and our Mask-con directly godless out without the transition effect, that is why the effect of our program, after some considerations bloggers found that in the case of display is none of our transition property may be invalid, then some of the small partners here may ask "blogger, That's not right, we have already set the mask display to block how can we still have this problem? "

So, our mask control shows that it takes a little bit of time to fully display it, but after our variable show is set to true, our shadow control and the main control are added immediately after the animated style class name, which is faster than the mask display time, So our machine it thinks mask is still in the display is none of the situation

For example: Mask is the boss of this whole piece, this old most have not performed, you do the younger brother has come out to rob the Thunder, you let the face of the boss where to put, not I have to take you these Rob my thunder all to kill, see you also have to. The boss of the people do not talk much, you rob his thunder, you do not want to show him (user experience) is not happy, and he finished not to tell you, the boss so difficult to wait to do? Some small partners have already felt confused, that still waiting for what, quickly pick up your hands of the phone call helpline .... Oh, yuck, it's far away.

In fact, the solution is very simple, yes the answer is setTimeout () function, we will change the code again:

Page ({data: {show:false,//) is used to show or hide the mask control runam:false//used for animation execution based on}, Chanmask:function () { var isshow = this.data.show? false:true;//If the display is hidden, hide it shows var delay = isshow?            30:1000;//The first time the blogger measured the time required for the control to display, the second is the time required for the animation if (isshow) {this.setdata ({show:isshow        });            }else{this.setdata ({runam:isshow})} setTimeout (function () {            if (isshow) {this.setdata ({runam:isshow});            }else{this.setdata ({show:isshow});    }}, delay); }}) <!--index.wxml--><view class= "container" ><button bindtap= "Chanmask" > Point me </button>< View Class= "Mask {{show?} ' Show ': ' Hide '} ' bindtap= ' Chanmask ' ><view class= ' Mask-shadow {{Runam? ' Mask-shadow-on ': '}} ' ></view><view class= ' Mask-con {{Runam? 'Mask-con-show ': '}} "><view class=" Close "bindtap=" Chanmask ">X</view> slowly fly </view></view ></view>

In the above code, we have added a new variable Runam to the data for when the animation starts executing, and then the Chanmask function defines a variable delay code that is used to set the delay. It might be a bit of a detour.

The whole process of the program is based on the variable of isshow.

When Isshow is true, that means we're going to open the mask control, so let's show the Mask control first, and then add the style class name to the control you want to animate after 30 milliseconds of delay.

When Isshow is false, we first remove the class name of the animation control (and then perform the animation back to its original shape), and then let mask hide after 1000 milliseconds of delay (the time it takes to animate)

About the first value of the delay set when the blogger himself, if the small partners are also worried that the control is not shown can be set to 50 milliseconds or 100 milliseconds without the impact of this 0.1 second time difference on the user experience is not big, such as you set a 1 seconds did not respond, I can only say change cell phone

Finally, you will find that throughout the process, bloggers only call a function to show or hide, and not to close the new function processing, this writing force is full of wood has

This method is also suitable for H5

The first time the new blog is a bit wordy, hope forgive me

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

Related Article

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.