鼠标光标在图像上的坐标:< br/>不工作 [英] Mouse cursor coordinates over image: <br/> not working

查看:147
本文介绍了鼠标光标在图像上的坐标:< br/>不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢我收到的建议这里,我清理了代码,现在使用纯jQuery.我对发现

thanks to the suggestions I received here, I cleaned up my code and I'm now using pure jQuery. I made slight edits to a script I found here and I've got this:

window.onload = function(){

    var tooltip = $( '<div id="tooltip">' ).appendTo( 'body' )[0];

$( 'img' ).
    each(function () {
        var pos = $( this ).position(),
            top = pos.top,
            left = pos.left,
            width = $( this ).width(),
            height = $( this ).height(); 
        $( this ).
            mousemove(function ( e ) {
                var x = e.pageX - left,
                    y = e.pageY - top;

                $( tooltip ).text( 'x = ' + x + ', y = ' + y ).css({
                    left: e.clientX + 10,
                    top: e.clientY + 10
                }).show();
            }).
            mouseleave(function () {
                $( tooltip ).hide();
            }); 

    });

};

我有一个问题:我尝试将代码的一行更改为:

I have a problem: I tried changing one line of my code to:

$( tooltip ).text( 'x = ' + x + '<br/> y = ' + y ).css({

但是它不起作用.我没有打破界限,而是得到了:

but it does not work. Instead of breaking the line, I get this:

推荐答案

更改:

$( tooltip ).text( 'x = ' + x + '<br/> y = ' + y ).css({

收件人:

$( tooltip ).html( 'x = ' + x + '<br/> y = ' + y ).css({

这篇关于鼠标光标在图像上的坐标:&lt; br/&gt;不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆