问题描述
有没有办法在不使用 JavaScript 的情况下延迟 :Hover 事件?我知道有一种方法可以延迟动画,但我没有看到任何延迟 :hover 事件的方法.
我正在制作一个类似傻瓜的菜单.我想在不增加额外 JS 权重的情况下模拟 hoverIntent 的作用.我更愿意将此视为渐进式增强,而不是让 JS 成为使用菜单的必要条件.
菜单标记示例:
<ul><li><a href="#"><ul><li></li><li></li></ul></li><li><li></ul></div></div>这里是完整的演示:http://jsfiddle.net/aEgV3/
解决方案 如果效果是基于 CSS 的,您可以使用过渡来延迟所需的 :hover 效果.
例如
div{过渡:0s 背景颜色;}div:悬停{背景颜色:红色;转换延迟:1s;}
这将延迟应用悬停效果(background-color 在这种情况下)一秒钟.
<小时>悬停开启和关闭延迟演示:
div{显示:内联块;填充:5px;边距:10px;边框:1px 实心#ccc;过渡:0s 背景颜色;转换延迟:1s;}div:悬停{背景颜色:红色;}
<div>延迟悬停</div>
仅在悬停时的延迟演示:
div{显示:内联块;填充:5px;边距:10px;边框:1px 实心#ccc;过渡:0s 背景颜色;}div:悬停{背景颜色:红色;转换延迟:1s;}
<div>延迟悬停</div>
<小时>过渡的供应商特定扩展和W3C CSS3 过渡
Is there a way to delay the :Hover event without using JavaScript? I know there is a way to delay animations, but I haven't seen anything on delaying the :hover event.
I'm building a son-of-suckerfish like menu. I'd like to simulate what hoverIntent does without adding the extra JS weight. I'd prefer to treat this as a progressive enhancement and not make JS a requirement for using the menu.
Example of menu markup:
<div>
<div>
<ul>
<li><a href="#">
<ul>
<li></li>
<li></li>
</ul>
</li>
<li>
<li>
</ul>
</div>
</div>
Here is the full demo: http://jsfiddle.net/aEgV3/
解决方案 You can use transitions to delay the :hover effect you want, if the effect is CSS-based.
For example
div{
transition: 0s background-color;
}
div:hover{
background-color:red;
transition-delay:1s;
}
this will delay applying the the hover effects (background-color in this case) for one second.
Demo of delay on both hover on and off:
div{
display:inline-block;
padding:5px;
margin:10px;
border:1px solid #ccc;
transition: 0s background-color;
transition-delay:1s;
}
div:hover{
background-color:red;
}
<div>delayed hover</div>
Demo of delay only on hover on:
div{
display:inline-block;
padding:5px;
margin:10px;
border:1px solid #ccc;
transition: 0s background-color;
}
div:hover{
background-color:red;
transition-delay:1s;
}
<div>delayed hover</div>
Vendor Specific Extentions for Transitions and W3C CSS3 transitions
这篇关于如何在 CSS 中延迟 :hover 效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
The End
相关推荐
1. 如果是ajax嵌套了 页面, 请确保 只有最外层的页面引入了layui.css 和 layui.js ,内层页面 切记不要再次引入 2. 具体代码如下 layui.use(['form', 'upload'], function(){ var form = layui.form; form.render(); // 加入这一句});...
2024-11-09
前端开发问题
313
问题描述 我想改变layui时间日历布局大小,这个要怎么操作呢? 解决办法 可以用css样式对时间日历进行重新布局,具体代码如下: !DOCTYPE htmlhtmlheadmeta charset="UTF-8"title/titlelink rel="stylesheet" href="../../layui/css/layui.css" /style#test-...
2024-10-24
前端开发问题
271
CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)...
2024-04-20
前端开发问题
13
getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)...
2024-04-20
前端开发问题
6
How do I make a TextGeometry multiline? How do I put it inside a square so it wraps like html text does inside a div?(如何制作 TextGeometry 多线?如何将它放在一个正方形内,以便它像 html 文本一样包裹在 div 内?) - IT屋-程序员软件开发技术分享社...
2024-04-20
前端开发问题
6
How to use coffeescript in developing web-sites?(如何在开发网站时使用coffeescript?)...
2024-04-20
前端开发问题
10
热门文章
1错误 [ERR_REQUIRE_ESM]:不支持 ES 模块的 require()
2vue中yarn install报错:info There appears to be trouble with you
3为什么 Chrome(在 Electron 内部)会突然重定向到 chrome-error://chromewebdat
4“aria-hidden 元素不包含可聚焦元素"显示模态时的问题
5使用选择器在 CSS 中选择元素的前一个兄弟
6js报错:Uncaught SyntaxError: Unexpected string
7layui怎么刷新当前页面?
8将模式设置为“no-cors"时使用 fetch 访问 API 时出错
热门精品源码
最新VIP资源
1多功能实用站长工具箱html功能模板
2多风格简历在线生成程序网页模板
3论文相似度查询系统源码
4响应式旅游景点宣传推广页面模板
5在线起名宣传推广网站源码
6酷黑微信小程序网站开发宣传页模板
7房产销售交易中介网站模板
8小学作业自动生成程序


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)