使用 CSS3 过渡延迟鼠标移开/悬停

发布于 2025-01-08 03:29:08 字数 254 浏览 4 评论 0原文

我有一个在悬停时会改变大小的盒子。但是,我想延迟鼠标移出阶段,以便框在恢复旧尺寸之前保持新尺寸几秒钟。

div {
    width: 70px;
    -webkit-transition: .5s all;    
}

div:hover {
    width:130px;
}

不使用 Javascript 而只使用 CSS3 是否可以做到这一点?我只需要关心支持webkit

I've got a box that changes size when being hovered. However, I would like to delay the mouseout stage, so that the box keep the new size for a few seconds, before getting the old size back.

div {
    width: 70px;
    -webkit-transition: .5s all;    
}

div:hover {
    width:130px;
}

Is this possible to do WITHOUT Javascript and only CSS3? I only have to care about supporting webkit.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深海少女心 2025-01-15 03:29:08
div {
    width: 70px;
    -webkit-transition: .5s all;   
    -webkit-transition-delay: 5s; 
    -moz-transition: .5s all;   
    -moz-transition-delay: 5s; 
    -ms-transition: .5s all;   
    -ms-transition-delay: 5s; 
    -o-transition: .5s all;   
    -o-transition-delay: 5s; 
    transition: .5s all;   
    transition-delay: 5s; 
}

div:hover {
    width:130px;
    -webkit-transition-delay: 0s;
    -moz-transition-delay: 0s;
    -ms-transition-delay: 0s;
    -o-transition-delay: 0s;
    transition-delay: 0s;
}

这将立即触发鼠标悬停状态,但请等待 5 秒,直到触发鼠标悬停。

小提琴

div {
    width: 70px;
    -webkit-transition: .5s all;   
    -webkit-transition-delay: 5s; 
    -moz-transition: .5s all;   
    -moz-transition-delay: 5s; 
    -ms-transition: .5s all;   
    -ms-transition-delay: 5s; 
    -o-transition: .5s all;   
    -o-transition-delay: 5s; 
    transition: .5s all;   
    transition-delay: 5s; 
}

div:hover {
    width:130px;
    -webkit-transition-delay: 0s;
    -moz-transition-delay: 0s;
    -ms-transition-delay: 0s;
    -o-transition-delay: 0s;
    transition-delay: 0s;
}

This will trigger the mouseover state right away, but wait 5 sec till the mouseout is triggered.

Fiddle

才能让你更想念 2025-01-15 03:29:08

转换可以声明为

transition: .5s all 5s

(简写,第一个数字是持续时间,第二个数字是延迟)
那么你不需要单独的转换延迟

抱歉,无法添加为评论,因为我没有足够的点

transition can be declared as

transition: .5s all 5s

(shorthand, the first number is duration, the second number is delay)
then you don't need the separate transition-delay

sorry, can't add as a comment as I don't have enough points

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文