伪衙门 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 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用