对于移动设备,我使用 :hover :active 在选项卡(单击)上创建过渡效果,增加元素的大小以提供更多信息。我希望激活的元素在一段时间过后再次变为“非活动”。我找不到类似的问题。
编辑:问题似乎是该元素现在永久“悬停”,我希望该元素在几秒钟后不悬停
edit2:http://jsfiddle.net/qw8vyrxd/
.box {
width: 40px;
height: 40px;
background-color: red;
}
@media screen and (max-width: 1000px){
.box:hover, .box:active{
width: 60px;
height: 60px;
}
}
在移动设备上,红色方块将在点击时展开(触发悬停选择器),但永远不会缩回,除非页面重新加载,我想要悬停效果仅持续几秒钟。
此致
for mobile I used :hover :active to create a transition effect on tab(click) that increases the size of the elements to give more information. I want the activated element to become "inactive" again after a certain time has elapsed. I was unable to find a comparable question.
edit: The problem appears to be that the element is now permanently "hovered", I would like the element to be not hovered after a couple seconds
edit2: http://jsfiddle.net/qw8vyrxd/
.box {
width: 40px;
height: 40px;
background-color: red;
}
@media screen and (max-width: 1000px){
.box:hover, .box:active{
width: 60px;
height: 60px;
}
}
on mobile the red square will expand on click ( triggering hover selector ) but will never retract unless page reloaded, I want the hover effect to only last a couple seconds.
Best regards
发布评论
评论(1)
触摸屏上元素上保留的状态是
:hover
(在我的情况下),而不是:active
。触摸屏保持:hover
状态,直到您单击其他位置。因此,我通过仅将
:hover
应用于支持它的设备(使用媒体查询悬停:hover)并保留:active
而不使用媒体来解决此问题查询。在触摸屏上,只要用户将手指放在元素上,:active
状态就会处于活动状态。这在我的设备上解决了这个问题。我必须使用真实设备,因为即使通过模拟触摸,DevTools 仍然表现得像鼠标。
延迟版本
由于伪状态很难用 JS 控制,所以我想只使用 CSS。我使用了一些walkaround-hack。我将
transition
设置为 0s,然后将transition-delay
设置为2s
。然后我为支持悬停的设备重载/禁用它。这意味着它在触摸屏上显示更大 2 秒。
The state that remains on the element on touch screen is
:hover
(in my situation), not:active
. Touch screen keeps the:hover
state until you click somewhere else.So I solved this by applying
:hover
only to the device that supports it (using media queries hover:hover) and leaving:active
without media queries. On touch screen state:active
is active for as long as the user has their finger on the element.This solved it on my devices. I had to use real devices because DevTools kept acting like mouse even through simulated touch.
Delayed version
Since pseudo states are difficult to control with JS, I wanted to use only CSS. I used a little walkaround-hack. I set
transition
to 0s and thentransition-delay
by2s
. Then I overloaded/disabled this for devices that support hover.It means it appears bigger on touch screen for 2 seconds.