开发者

How could I make a popup once user highlights a word?

I would like to make a popup that is related to the word (or words) that the user highlights. Like the user highlights this and then a popup jumps u开发者_StackOverflowp and says: "Leart more about 'this'. View articles related to this (or these) words."

How could I do this?


HTML

<p>Lorem ipsum dolor sit amet, <a class="popuplink" href="#">consectetur </a>adipiscing elit. Maecenas sed lectus nec risus volutpat gravida. Duis dapibus felis lobortis et lobortis nulla ornare. Suspendisse eu mi tempus magna volutpat elementum vel vitae enim. Maecenas feugiat feugiat tincidunt. Suspendisse eu rhoncus dolor. Cras porta, arcu sagittis porta, ligula odio tristique lorem, id sagittis risus velit nec elit. Sagittis lacus scelerisque mauris rhoncus ut porttitor quam cursus. Praesent nec risus non nunc imperdiet a augue. Etiam ut elit eu metus placerat semper. Nam volutpat massa sed lorem vestibulum at vehicula dui fermentum. Etiam condimentum pretium tincidunt. Nullam nec placerat ligula.</p>

<div id="tooltip"></div>

Jquery

var $tooltip = $('#tooltip'), // reusable jQuery obj
    offset = {x: 20, y: 20}; // tooltip offset from the cursor

$('a').mouseover(function() { // over
    $tooltip.show()
}).mousemove(function(e) { // move
    // set the positioning with offset
    $tooltip.css({left: e.pageX + offset.x, top: e.pageY + offset.y})
    // set the tooltip HTML contents
    $tooltip.html('Learn more about this...');
}).mouseout(function() { // out
    $tooltip.hide();
});

CSS

.popuplink{color: #0066cc; background: #CACAC6;}
#tooltip{position: absolute; padding: 10px; border: 1px solid #ccc; background: #fff}

Example


you can use Apture HighLights

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜