on how to implement custom native control styles in mobile phone-side web front-end

Source: Internet
Author: User

Mobile phone Development WebApp's classmates must have encountered such a problem, how to apply custom styles for the ugly phone elements. First, to figure out why you want to define the style of your phone's native controls, you need to look at the ugly touch of the native box style of your phone:

Android:

Ios:

The choice of helpless

After reading these ugly interface elements, we can understand that when we expose them to the eyes of the product classmate, that layer of murderous. You can see that the interface element is very ugly, the product brother is certainly not acceptable. However, it has to be said that the effects of these controls are more cool when triggered than on a PC. This is the best choice for the Apple machine drum. The following are the effects of invoking native controls after they are triggered:

Android:

Ios:

We have to say that these style native pop-up styles are in accordance with our design principles, because it embodies the UI interface of friendliness and experience, without loss of any Web performance, the key is that we do not need to do anything. Product BZJ You see, specify the effect of the drum under the Apple machine to select the date or down order. If we can't solve the problem of the style of the interface text box, then no matter how cool the effect is, it always makes people unacceptable. Maybe you'd like to take the time to write a similar effect? I don't deny that you can write it, but how much time does it take to work? Also a lot of people choose the plug-in way. Through the JQ plugin (if your project is not in use JQ, in order to download JQ and its plug-in for this effect) to achieve, in fact, is very thankless thing. One is the plug-in this thing out of the question or change the demand after it will become abnormally bad expansion, the second is of course to consider the resource load, on the phone side especially need to consider. Therefore, the choice of plugins is the next worst!

Workaround

The problem is that you want the cool effect of the popup layer and the style that the control displays in the interface. What do we do? Dewdrops have tried the simplest way to rewrite the CSS to change their style, but even after several hours in Google, no satisfactory results have been found. The Dewdrop also tried the-webkit-appearance attribute, but it also seemed unsatisfactory. Besides, we need compatible multi-models (Android, Apple, WP?) )。 In any case, it does not work to change the original style of the road. Dew after thinking, found a very good solution, but also the topic of this blog post: Since the control in the page style can not be changed, then hide it, but! Instead of hiding it with display:none, or setting width and height to 0, we want to keep the tap and focus events on them without seeing their original style. But in addition to the above methods, what can make them invisible? You must have thought of it, yes, that's opacit:0. By setting the control's opacity to 0, we can let the element continue to leave it on the interface and remain responsive to the state of the focus event at any time. What we're going to do is set the control to absolute positioning, overriding it on an element of our custom style. This way, the user sees the element underneath, but when his hand touches the element, he actually touches the original control that is completely clear on the interface! As shown in the following:

This is the first step, then we need to bind the response event for the control, in most cases we need to bind the event is onchange, once the selection is done, the value is copied to the custom element. It's done! Whether you submit by Form or post, the value you get is still the value of the control, the custom element is only responsible for displaying, not responsible for the business!

Code implementation
Conclusion

Product B June saw the ugly things disappear, iOS under the drum and cool roll up, will certainly pat your shoulder said the brother did well. This blog post is not just about solving the style of the control, but in other similar situations, it is worthwhile to use masking layers to mask your inability. In fact, in the development of the kind of small tricks, as long as found the know-how and methods, a line of code is worth 10,000 lines of code (borrow Liu Zhenyun's novel name). Although it is a small trick, a large portion of a blog to explain is too exaggerated and cumbersome, but the front-end development of the detail, I hope to encounter similar problems or future needs to solve the students have help.

on how to implement custom native control styles in mobile phone-side web front-end

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.