伪衙门 2017-02-24 08:58 采纳率: 38.5%
浏览 836

jQuery拖拽之右键菜单

图片说明
主要用意图片上可以看一下。
代码如下:

HTML代码:
 <div id="toolbar" style="position:inherit;float:inherit;height:100%;width:50px;">
            <ul style="padding:0px;margin-top:80px;margin-left:10px;">
                <li style="list-style-type:none">
                    <a id="item" href=" #" class="item">
                    <img src="~/resource/images/user/video.jpg" />
                    </a>
                </li>
                <li style="list-style-type:none">
                    <a id="item" href=" #" class="item">
                        <img src="~/resource/images/user/yo.jpg" />
                    </a>
                </li>
            </ul>
        </div>
        <div id="canvas" style="position: inherit; float: inherit; border: 2px dashed #ccc; height: 100%; width: 1000px; ">
            <img src="~/resource/images/user/alarm.jpg" style="position: inherit; float: inherit;" />
        </div>


JavaScript代码如下:
                $('.item').draggable({
            revert: true,
            proxy: 'clone',
            cursor:'move',
            onStartDrag: function () {
                $(this).draggable('options').cursor = 'not-allowed';
                $(this).draggable('proxy').css('z-index', 10);
            },
            onDrag: function(e){
                document.getElementById("idShow").innerHTML = "left:" + e.clientX + ";top:" + e.clientY;
                dragX = e.clientX-64;
                dragY = e.clientY-58;
            },
            onStopDrag: function () {
                $(this).draggable('options').cursor = 'move';
            }
        });

        $('#canvas').droppable({
            onDragEnter: function (e, source) {
                $(source).draggable('options').cursor = 'auto';
            },
            onDragOver: function () {

            },
            onDragLeave: function (e, source) {
                $(source).draggable('options').cursor = 'not-allowed';
            },
            onDrop: function (e, source) {

                var c = $(source).clone(); //c对应图中的A1 
                c.css("z-index", "100").css("position", "absolute").css("left", dragX).css("top", dragY);
                $(this).append(c);
            }
        });
  • 写回答

1条回答 默认 最新

  • threenewbee 2017-02-24 15:07
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记