使用Fokus的模态样式文本选择

Every once in a while I find a tiny JavaScript library that does something very specific, very well.  My latest find, Fokus, is a utility that listens for text selection within the page, and when such an event occurs, shows a beautiful modal dialog in the background of the entire page, allowing only the highlighted block to display at it's normal mode.

偶尔我会发现一个很小JavaScript库,它做的非常好,非常好。 我的最新发现Fokus是一种实用程序,可侦听页面中的文本选择,并且当发生此类事件时,它会在整个页面的背景中显示漂亮的模式对话框,仅允许突出显示的块以其正常模式显示。

HTML (The HTML)

Nothing special needs to be done with the page HTML, and you don't create "active" zones -- simply include the JavaScript file at the bottom of the page:

页面HTML不需要做任何特别的事情,并且您无需创建“活动”区域-只需在页面底部添加JavaScript文件即可:


<!-- at bottom of the page -->
<script src="fokus/js/fokus.min.js" async></script>


The overlay elegantly fades in and out.  Canvas is used to create the overlay, and CSS' pointer-events property is used to ensure event handling consistency.  It would be great if Fokus was a bit more modular, including allowing active zones and customized overlay color, but it's hard to complain about anything else with Fokus.

覆盖层淡入淡出。 Canvas用于创建叠加层,而CSS的pointer-events属性用于确保事件处理的一致性。 如果Fokus更具模块化,包括允许活动区域和自定义的覆盖颜色,那就太好了,但是Fokus很难抱怨其他任何事情。

Fokus isn't a necessity for any site, but I was taken aback by how smooth and accurate Fokus is.  Weighing in at just 3KB, it's an impressive little library.  Have an idea for how you'd use Fokus?  Share it!

Fokus并不是任何站点的必需品,但是Fokus如此平滑和准确使我感到惊讶。 它只有3KB的重量,是一个令人印象深刻的小图书馆。 有一个关于如何使用Fokus的想法吗? 分享它!

翻译自: https://davidwalsh.name/fokus

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值