Click on the desktop side to achieve increased background color, move end items touch to add a background color, but the mouse and your finger from the background color need to recover

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        p:active {
            background-color: red;
        } 
    </style>
</head>
<body>
    <p >p:active</p>
    <script>
        document.querySelector('p').addEventListener('touchstart', function () { 
            this.style.backgroundColor = 'red'
         });
        document.querySelector('p').addEventListener('touchend', function () { 
            this.style.backgroundColor = 'transparent'
         });
         document.querySelector('p').addEventListener('mousedown', function () { 
            this.style.backgroundColor = 'red'
         });
         document.querySelector('p').addEventListener('mouseup', function () { 
            this.style.backgroundColor = 'transparent'
         });
    </script>
</body>
</html>

Guess you like

Origin www.cnblogs.com/wangdong9395/p/12372896.html