Create Safari's Find Function Style Text Selector in Javascript
Is there any way开发者_StackOverflow to make this text selection effect easily with a library in Javascript? It is very well done and I'd like to mirror this look.
Wondering if anyone had done something similar or seen it done before and if they could provide any guidance. Thanks!
- on-page text highlighting Search with jQuery and
- On-Page Text Search.
The style is quite similar to the Safari implementation.
You can use window.find()
in most browsers and TextRange
's findText()
method in IE to find all occurrences of a particular string in the page, and then use execCommand()
to style each occurrence. See Full text search in HTML ignoring tags / & for an example. This won't give you the curvy corners and drop shadow but is a starting point. It also doesn't work in Opera.
精彩评论