为什么设置画布样式光标仅对某些而不是全部起作用?

时间:2018-11-24 02:16:34

标签: javascript html css canvas

enter image description here

enter image description here

我认为只要光标位于路径中,它就会生效。但这不是事实,为什么? 我希望众神会回答 这是我的部分代码

        addMouseMove();
        function addMouseMove(){
            canvas.addEventListener("mousemove",function(e){
                e = e || window.event;
                if( e.offsetX || e.offsetX==0 ){
                    mousePosition.x = e.offsetX;
                    mousePosition.y = e.offsetY;
                }else if( e.layerX || e.layerX==0 ){
                    mousePosition.x = e.layerX;
                    mousePosition.y = e.layerY;
                }
                mouseTimer = setTimeout(function(){
                    ctx.clearRect(0,0,canvas.width, canvas.height);
                    drawLineLabelMarkers();
                    drawBarAnimate(true);
                    drawDragBar();
                },10);
            });
        }


        function initChart(){
            canvas.width = cBox.getAttribute("width")* 2 ;
            canvas.height = cBox.getAttribute("height")* 2;
            canvas.style.height = canvas.height/2 + "px";
            canvas.style.width = canvas.width/2 + "px";
        function drawRect( x, y, X, Y, mouseMove , color){
            ctx.beginPath();
            ctx.rect( parseInt(x), parseInt(y), parseInt(X), parseInt(Y) );
            if(ctx.isPointInPath(mousePosition.x*2, mousePosition.y*2)){
                canvas.style.cursor = "all-scroll";
            }else
                canvas.style.cursor = "default";
            ctx.fillStyle = color;
            ctx.fill();

        }
        function drawDragBar(){
            drawRect( originX, originY+cSpace, cWidth, cMargin, false, "#E8E4F0");
            drawRect( originX, originY+cSpace, dragBarX-originX, cMargin, false, "#BCCEF5");
            drawRect( dragBarX, originY+cSpace, dragBarWidth, cMargin, false, "#078ACB",false,true);
        }

0 个答案:

没有答案