2
            <script type="text/javascript" src="jquery-2.0.3.min.js"></script>
            <style>
            .canvas {
                position:relative;
                height:550px;
                width:400px;
                background:Yellow url("http://www.mapstop.co.uk/images/uploaded/lrg_wg2668.6a40d0d.jpg") no-repeat;
            }
            .canvas img {
                position:absolute;
            }
            </style>
            <div class="toolbar">
            <span>Drag...</span>
            <img src="https://i.stack.imgur.com/hoEOi.png" alt="" title="" />
            <img src="http://cdn4.iconfinder.com/data/icons/iconsland-weather/PNG/48x48/Thermometer_Snowflake.png" alt="" title="" />
            <img src="http://cdn4.iconfinder.com/data/icons/iconsland-weather/PNG/48x48/Overcast.png" alt="" title="" />
            <img src="http://cdn4.iconfinder.com/data/icons/iconsland-weather/PNG/48x48/Night_Rain.png" alt="" title="" />
            </div>
            <div class="canvas"></div>
            <script type="text/javascript">
            $(document).ready(function () {
                var $toolbar = $(".toolbar");
                var $tools = $toolbar.find("img");

                //define drag and drop handlers
                $toolbar.on("dragstart", "img", onDrag);

                $(".canvas").on({
                    dragenter: false,
                    dragover: false,
                    drop: onDrop
                });

                //handle commencement of drag
                function onDrag(e) {

                    console.log("onDrag");
                }

                //handle drop
                function onDrop(e) {

                    //console.log("OnDrop");
                    //console.log(e.clientX);
                    //console.log(e.clientY);
                    //console.log(e.originalEvent);
                }
            });
            </script>

当我放下图像时,出于某种原因,我被转发到http://cdn4.iconfinder.com/data/icons/iconsland-weather/PNG/48x48/Sunny.png但仅限于 FireFox。Chrome 和 IE 似乎都采取了预期的行为,即现在什么都不做。也许有人可能知道为什么会这样?

4

1 回答 1

1

尝试为拖入指定处理程序并拖动并添加e.preventDefault();e.stopPropagation();您的处理程序。

于 2013-10-06T00:37:32.020 回答