intelogie/caret.js

该软件包最新版本(dev-master)没有提供许可信息。

维护者

详细信息

github.com/INTELOGIE/Caret.js

源代码

安装: 112

依赖者: 0

建议者: 0

安全性: 0

星标: 0

关注者: 2

分支: 162

语言:JavaScript

dev-master 2016-07-21 14:42 UTC

This package is auto-updated.

Last update: 2024-09-21 20:20:45 UTC


README

获取输入框的 caret 位置或偏移量

这是在 At.js 中工作的核心功能。
现在,它已成为一个简单的 jQuery 插件,以便每个人都可以使用。
当然,At.js 也使用了这个插件。

  • 支持 iframe 上下文

在线演示

http://ichord.github.com/Caret.js/

用法

// Get caret position
$('#inputor').caret('position'); // => {left: 15, top: 30, height: 20}

// Get caret offset
$('#inputor').caret('offset'); // => {left: 300, top: 400, height: 20}

var fixPos = 20
// Get position of the 20th char in the inputor.
// not working in `contentEditable` mode
$('#inputor').caret('position', fixPos);

// Get offset of the 20th char.
// not working in `contentEditable` mode
$('#inputor').caret('offset', fixPos);

// more

// Get caret position from the first char in the inputor.
$('#inputor').caret('pos'); // => 15

// Set caret position in the inputor
$('#inputor').caret('pos', 15);

// set iframe context
// NOTE: Related to the iframe's cooridinate.
//       You might want to get the iframe's offset/position on your own
$('#inputor').caret('offset', {iframe: theIframe});
$('#inputor').caret('position', {iframe: theIframe});
$('#inputor').caret('pos', 15, {iframe: theIframe});