在图像映射上拖放元素获取值

时间:2013-07-09 19:46:48

标签: jquery imagemap

我有一张图片地图,想要拖放一个元素,即国家地图上的图钉。当针在地图上掉落时。我需要那张图片地图ID。

<p id="draggable" style="position: absolute; bottom: 10px; left: 40px; cursor: move; z-index:100;"><img src="images/pin1.png"/></p>
<img src="image.gif" width="145" height="126" alt="Elements" usemap="#elementmap" />
    <map name="elementmap">
    <area id="element1"  class="droppable" shape="rect" coords="0,0,82,126" alt="Element 1"/>
    <area id="element2" class="droppable" shape="circle" coords="90,58,3" alt="Element 2"/>
</map>

jQuery代码是这样的:

$("#draggable").draggable();
$(".droppable").droppable({
    accept: '#draggable',
    activeClass: "ui-state-hover",
    hoverClass: "ui-state-active",
    drop: function (event, ui) {
        var targetElem = $(this).attr("id");

        var draggableId = ui.draggable.attr("id");
        var droppableId = $(this).attr("id");

        alert(targetElem);
        alert(draggableId);
        alert(droppableId);

    }
});

这是jsFiddle示例: http://jsfiddle.net/fguru/ZKQ2x/2/

有没有办法解决。

1 个答案:

答案 0 :(得分:-1)

http://www.w3schools.com/html/html5_draganddrop.asp

尝试将draggable="true"属性添加到您的img标记