问一下大家,有谁了解:在浏览器当前页面,按着鼠标右键滑动,页面上会有鼠标滑动的轨迹(线条)出现,这种效果是怎么实现的?

解决方案 »

  1.   

    我们有个基于HTML5的类似功能。实现估计类似。js监听鼠标右键摁下,监听鼠标移动,监听鼠标抬起。在移动的方法中做绘制。
      

  2.   

    就是判断鼠标右键啊设置一个变量保存鼠标状态
    按下了,记录一下起点坐标,设置变量为true,
    移动了,记录一下新位置的坐标,把此坐标跟上一个坐标连接(如果没有,连接起点坐标)起来,
    松开了,记录一下终点坐标,把终点坐标跟上一个坐标连接起来(就是移动的时候不停的记录下的坐标取最后一个),设置状态变量为false。用canvas,svg,vml来做比较简单吧。。不然用纯js+html标签画出来的效果不是很好。
      

  3.   

    不一定非要html5
    <script>
        window.onload = function(){
            document.onmousedown=function(e){
                e=e||window.event;
                if(2==e.button){
                    document.onmousemove = function (e) {
                        var oe = e || window.event;
                        var div = document.createElement("div");
                            div.className="li";
                            div.style.left=oe.clientX + "px";
                            div.style.top=oe.clientY + "px";
                        document.body.appendChild(div);
                    };
                    document.onmouseup = function () {
                        document.onmousemove =  null;
                    };
                }
            };
        };
        </script>
      

  4.   

    补上样式:    <style>
            .li{position: absolute;width: 2px;height:2px;background-color: #000}
        </style>