【问题标题】:Crossbrowser GRAB cursor (-moz, -webkit)跨浏览器抓取光标 (-moz, -webkit)
【发布时间】:2015-09-21 08:17:03
【问题描述】:

我正在尝试自定义光标的行为。现在它以另一种方式工作:在 mousemove 上我使用:

scheme.setAttribute("cursor", "move");

鼠标上移:

scheme.setAttribute("cursor", "auto");

在这种情况下:

scheme.setAttribute("cursor", "-moz-grab");
scheme.setAttribute("cursor", "-webkit-grab");

光标仅适用于 -webkit(Chrome)

在这种情况下

scheme.setAttribute("cursor", "-webkit-grab");
scheme.setAttribute("cursor", "-moz-grab");

光标仅适用于-moz(FF)

以下结构没有按我的预期工作:

scheme.setAttribute("cursor", "-moz-grab, -webkit-grab");

这行得通:

scheme.setAttribute("style", "cursor:-moz-grab; cursor:-webkit-grab;");

在这两种浏览器中,但我 read here 认为这是不好的做法。


代码here 有效,但我需要使用thisthat 之类的结构。

this 之类的东西(该结构现在不起作用)。


编辑 1

来自other Stack Overflow post

解决方案:

scheme.setAttribute("cursor", "url(http://www.google.com/intl/en_ALL/mapfiles/openhand.cur) 4 4, move");

适用于两种浏览器,但仍需要使用 -moz-grab-webkit-grab 值的解决方案。

link here

而且它似乎在 IE 中不起作用(我希望看到第二个,保留移动图标)


编辑 2

更清晰的 mousedown/mouseup 示例:

Case 1:(仅适用于 Chrome)

Case 2:(这里mousedown没有变化)

【问题讨论】:

    标签: javascript html css dom mouse-cursor


    【解决方案1】:

    按照 J.Steve 的回答:

    .grabbable {
        cursor: move; /* fallback if grab cursor is unsupported */
        cursor: grab;
        cursor: -moz-grab;
        cursor: -webkit-grab;
    }
    
     /* (Optional) Apply a "closed-hand" cursor during drag operation. */
    .grabbable:active { 
        cursor: grabbing;
        cursor: -moz-grabbing;
        cursor: -webkit-grabbing;
    }
    

    从这里CSS for grabbing cursors (drag & drop) 还有这个cmets

    您确定逗号列表仍然有效吗?我正在使用光标:移动; 光标:-webkit-grab;光标:-moz-grab;光标:抓取;与大多数 首选最后一个

    如果您指定多种格式,如 光标:url(example.svg#linkcursor)、url(hyper.cur)、指针

    就我而言,我设置了 CCS 选项

    item.setAttribute("style", "cursor: move; cursor: grab; cursor:-moz-grab; cursor:-webkit-grab;");

    并通过

    取消设置

    item.setAttribute("style", "cursor: auto;"); 在我的取消事件(mouseup) 之后。


    http://jsfiddle.net/gwau7r9r/

    JS:

    var item = document.getElementById("changeCurArea");
        item.addEventListener("mousedown", func, false);
        item.addEventListener("mouseup", func1, false);
    
        function func() {
            item.setAttribute("style", "cursor: move; cursor: grab; cursor:-moz-grab; cursor:-webkit-grab;");
        }
    
        function func1() {
            // item.setAttribute("cursor", "auto");
            item.setAttribute("style", "cursor: auto;");
        }
    

    HTML:

    <svg xmlns="http://www.w3.org/2000/svg" width="400" height="350" viewBox="200 150">
        <rect id="mySvgArea" width="400" height="350" stroke="black" fill="lightgrey"></rect>
        <rect id="changeCurArea" x="100" y="100" width="200" height="150" stroke="red" fill="pink"></rect>
    </svg>
    

    【讨论】:

      猜你喜欢
      • 2012-06-13
      • 2012-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-28
      • 2012-06-03
      • 1970-01-01
      相关资源
      最近更新 更多