我正在使用HTML / jquery / CSS并且有一段文字 - “test”。
如何使“测试”文本跟随鼠标指针(如果更容易,则用文本替换鼠标指针图标)?
编辑来自Tims回答:CSS: #follower { background: #fff; padding: 5px; border: 1px solid #ddd; position: absolute; }
JS: $(document).ready(function(){
$("#follower").hide();
$(document).mousemove(function(e){
$("#follower").show();
$("#follower").css({
top: (e.pageY + 15) + "px",
left: (e.pageX + 15) + "px"
});
});
});
答案 0 :(得分:1)
您可以使用mousemove事件捕获鼠标的位置,然后设置为文本范围。
Html:
<html>
<body onmousemove="mousemove()">
<span id="textSpan" style="position:absolute">test</span>
</body>
</html>
js:
function mousemove()
{
$('#textSpan').css({
'top' : event.pageY,
'left' : event.pageX
});
}
答案 1 :(得分:0)
<div id="demo-mouse" class="box">
<h3>Hover over this box to see mouse tracking in action</h3>
</div>
$(document).ready(function()
{
$('#demo-mouse').qtip({
content: 'I position myself at the current mouse position',
position: {
my: 'top left',
target: 'mouse',
viewport: $(window), // Keep it on-screen at all times if possible
adjust: {
x: 10, y: 10
}
},
hide: {
fixed: true // Helps to prevent the tooltip from hiding ocassionally when tracking!
},
style: 'ui-tooltip-shadow'
});
});