Changing :hover to touch/click for mobile devices

后端 未结 9 1976
余生分开走
余生分开走 2020-11-28 19:43

I\'ve had a look around but can\'t quite find what i\'m looking for.

I currently have a css animation on my page which is triggered by :hover. I would like this to c

9条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 20:35

    A CSS only solution for those who are having trouble with mobile touchscreen button styling.

    This will fix your hover-stick / active button problems.

    body, html {
      width: 600px;
    }
    p {
      font-size: 20px;
    }
    
    button {
      border: none;
      width: 200px;
      height: 60px;
      border-radius: 30px;
      background: #00aeff;
      font-size: 20px;
    }
    
    button:active {
      background: black;
      color: white;
    }
    
    .delayed {
      transition: all 0.2s;
      transition-delay: 300ms;
    }
    
    .delayed:active {
      transition: none;
    }

    Sticky styles for better touch screen buttons!

    The CSS :active psuedo style is displayed between the time when a user touches down (when finger contacts screen) on a element to the time when the touch up (when finger leaves the screen) occures. With a typical touch-screen tap interaction, the time of which the :active psuedo style is displayed can be very small resulting in the :active state not showing or being missed by the user entirely. This can cause issues with users not undertanding if their button presses have actually reigstered or not.

    Having the the :active styling stick around for a few hundred more milliseconds after touch up would would improve user understanding when they have interacted with a button.

提交回复
热议问题