简体   繁体   中英

Mobile devices touch event with css

I have made a simple card system with mobile.

When I use below code, touch event detect very well.

 html, body { margin: 0; padding: 0; } .card1 { height: 200px; width: 200px; background-color: green; } .card1:active { background-color: blue; }
 <html> <body ontouchstart=""> <div class="wrap"> <div class="card1"></div> </div> </body> </html>

Not only in mobile devices but also works fine in the desktop.

But after detach the finger from the screen, it return to original state.

My goal is if I click touch the box, box will be changed to background-color: blue; and do not have to return background-color: green;

Is there any solution here?

Thanks.

It can be achieved by applying background color on click event using js

 $('.card1').click(function() { $('.card1').css({ 'background-color': 'blue', }); });
 html, body { margin: 0; padding: 0; } .card1 { height: 200px; width: 200px; background-color: green; }
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <html> <body ontouchstart=""> <div class="wrap"> <div class="card1"></div> </div> </body> </html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM