2017-05-22 12 views
-1

ハイライトされたテキストのXおよびY位置をマウスで現在のアクティブなWebページに表示できますか?ハイライトされたテキストの位置を取得することは可能ですか?

jQueryでこれを達成する方法を教えてください。

+0

特定のシナリオが必要ですか? (ごめんなさい...) – T30

+0

このプラグインの特徴は次のとおりです。http://annotatorjs.org/ – clearshot66

+0

https://github.com/Phoenix404/SwipeDetector/blob/master/SwipeDetector.js –

答えて

0

このJavascriptライブラリrangeblockを確認することができます。

テキスト範囲のレイアウトを特定し、測定し、表現することができます。

// TypeScript 
import * as rb from "rangeblock" 

// measure layouts 
let block = rb.extractSelectedBlock(window, document); 
if (!block) { 
    console.error("please select some text on the web page"); 
    return; 
} 
console.info("Text layout: " + JSON.stringify(block.dimensions)); 

// representation of the text range 
console.info("Text layout: " + JSON.stringify(block.rangeMeta)); 

// recreate range using RangeMeta 
let meta :RangeMeta = ... ; 
block = rb.restoreBlock(window, document, meta); 
-1

あなたはIE9を必要としない場合の例:

s = window.getSelection(); 

は選択を返します。だから試してみてください

s = window.getSelection(); 
oRange = s.getRangeAt(0); //get the text range 
oRect = oRange.getBoundingClientRect(); 

oRectは、クライアント(固定)座標の外接矩形になります。

From this answer here

関連する問題