Combining CSS and JavaScript to realize the screen sliding effect of mobile phone

Source: Internet
Author: User

I'm in a good mood today, so write a blog. Today I am here to share with you on the mobile phone screen switching effect hope to help some students just contact JS

Well, not much, on the code.

We first set up a parent container div and then it contains the sub-containers and then adds class to them.

I've defined their layout here, and then we'll set the style.

Okay, here's the first. Defines a style for the parent container and then defines the style for the child container

Here it is. The basic layout has been written and then, depending on your preferences, to change the background color of each phone screen or to add styles to the style.

The background color is finished. That's how I got a few colors. And then we'll look at the effect of the style. Of course, I opened it here with Google Chrome.

After running open, click on the above tips below to have the effect above I choose the type of phone is iphone6s you can choose according to your choice to select the phone model you want here the default is the first page is the first one we define <DIV class=page></ div> background color is red of course we can write the relevant content and style according to the project requirement after we work.

All right, we're finished with the fixed page style. And then we'll use our JavaScript to do the switching effect. We insert the script tag

We'll get all the container here and then declare two variables start, ENT

Then add two events to it Touchstart and touchmove trigger and continuous trigger when the finger is placed on a click

Of course we have a click to swipe also to have the finger leave when good we look at the following

So much has been said about the effect we're looking for.

We just said the first default screen is red, right? That's the following:

A second screen

A third

Fourth one

Fifth one

What we're setting here is the x-axis horizontal switch. If we want it to go down, it's pretty straightforward to rewrite H to V on top of the parent container, because we set the horizontal direction in the style is H vertical reverse is v so we can change it to remember oh want to screen switch with the computer mouse click slide in  Release it to achieve the effect. Having said so much hope can help the students

Combining CSS and JavaScript to realize the screen sliding effect of mobile phone

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.