登录

javascript - JS在空白页面移动如何改变鼠标样式

本来想做一个类似于像用鼠标控制windows窗口大小的功能,虽然后来功能可以实现,但是引申出一个疑问就是,怎么在空白页面鼠标移动时来改变鼠标样式呢?比如说这段代码,当clientX大于300时改变鼠标样式,我是加在了body身上,也没什么用,但是我加在document上直接就报错,说document是undefined

window.onload = function() {
    document.onmousemove=function(ev){
        var ev=ev||event;
        if(event.clientX>300){
            document.style.cursor='w-resize';
        }else
            document.style.cursor='auto';
    };
};
# JavaScript
ringa_leeringa_lee2146 天前361 次浏览

全部回复(1) 我要回复

  • PHP中文网

    PHP中文网2017-04-11 09:20:21

    document.body.style.cursor='w-resize'

    或者

    document.documentElement.style.cursor='w-resize'

    回复
    0
  • 取消回复发送