jQueryのselectイベントを入力し、テキストエリアに制限されているポップアップの高さによって、それを減らします。
文書全体でselect eventを検出する簡単な方法はありません。IEにはすべての要素に実装された選択イベントがありますが、他のブラウザでは入力のみがあります。あなたのページでキーアップとマウスアップイベントを処理することでそれを行うことができます。
ここに例を示します
example.Selector = {};
//each browser has a paricular getSelection .
example.Selector.getSelected = function(){
var t = '';
if(window.getSelection){
t = window.getSelection();
}else if(document.getSelection){
t = document.getSelection();
}else if(document.selection){
t = document.selection.createRange().text;
}
return t;
}
//bind a mouseup event handler to document
example.Selector.mouseup = function(){
var st = example.Selector.getSelected();
if(st!=''){
//display yout tooltip or popup here
}
}
$(document).ready(function(){
$(document).bind("mouseup", example.Selector.mouseup);
});
ここでの実施例は、私が全部を書き出すための時間を持っていないが、あなたはmouseup
のいくつかの組み合わせを使用することができるかもしれませんhttp://jsfiddle.net/chemouna/k6yVC/
「選択されたテキスト」とは、ユーザーがマウスで選択したテキストを意味しますか? – mariogl
@marioglはいそれは – DavidW