将图像添加到另一个图像上并获取坐标,使其可拖动并可删除

时间:2012-11-06 03:37:30

标签: jquery coordinates draggable appendto

在这里输入代码hereenter code`ok所以我有一个图像,我只需点击一个按钮就可以将另一个图像附加到它上面。图像附加,我得到位置的坐标。我也使用jquery ui制作了图片draggalbe。每次附加图像时,还会生成一个div,其中包含所单击的图像的坐标和区域。在新生成的div中有一个删除按钮,删除该分区。我需要使删除按钮也删除与该div对应的特定图像。我非常感谢有关此感谢的任何帮助。

<!DOCTYPE html>
<html>
    <head>
                <meta charset="utf-8" />
                    <title>MyMapImage</title>
                <style type="text/css">
                    #container {
                        background: green;
                        width: 596px;
                        height: 218px;
                        position: relative;
                        cursor: crosshair;

                    }
                    #container img {
                        position: absolute;  
                            opacity:0.95;
                    }

                    #container img.cross {
                        position: absolute;  

                    }
                </style>
                <style type="text/css">
        #draggable {font-size:x-large; border: thin solid black; width: 5em; text-align: center}
    </style>



                <script type="text/javascript">
                    $(document).ready(function() {
                    $(".WindSh").click(function(e) {
                        e.preventDefault();
                        var x = e.pageX - this.offsetLeft;
                        var y = e.pageY - this.offsetTop;
                        var img = $('<img>');
                        img.css('top', y-23);
                        img.css('left', x-23);
                        img.attr('src', 'cross.png');
                        img.attr('class','cross');
                        img.appendTo('#container');
                        img.draggable({
                        containment: "parent"
                        });
                    })

                });
                </script>
                <script type="text/javascript">

                    $(document).ready(function() {
                      $('.WindSh').click(function(e) {
                        var offset = $(this).offset();
                        var xz= e.clientX - this.offsetLeft;
                        var yz= e.clientY - offset.top;

                        if (parseInt(xz)>= 38 && parseInt(xz)<=200 && parseInt(yz)>=15 && parseInt(yz)<=98)
                        {
                        $('<div/>').append((xz) + ", " + (yz) + " ; " + "You have selected Region 1")
                        .appendTo('#coordinates');    
                        }
                        else if (parseInt(xz)> 200 && parseInt(xz)<=401 && parseInt(yz)>=15 && parseInt(yz)<=98)
                        {
                        $('<div/>').append ((xz) + ", " + (yz) + " ; " + "You have selected Region 2")
                        .appendTo('#coordinates');

                        }
                        else if (parseInt(xz)> 401 && parseInt(xz)<=540 && parseInt(yz)>15 && parseInt(yz)<=98)
                        {
                        $('<div/>').append ((xz) + ", " + (yz) + " ; " + "You have selected Region 3")
                        .appendTo('#coordinates');
                        }
                        else if (parseInt(xz)> 12 && parseInt(xz)<=200 && parseInt(yz)>98 && parseInt(yz)<=186)
                        {
                        $('<div/>').append ((xz) + ", " + (yz) + " ; " + "You have selected Region 4")
                        .appendTo('#coordinates');
                        }
                        else if (parseInt(xz)> 200 && parseInt(xz)<=401 && parseInt(yz)>98 && parseInt(yz)<=186)
                        {
                        $('<div/>').append ((xz) + ", " + (yz) + " ; " + "You have selected Region 5")
                        .appendTo('#coordinates');
                        }
                        else if (parseInt(xz)> 401 && parseInt(xz)<=540 && parseInt(yz)>98 && parseInt(yz)<=186)
                        {
                        $('<div/>').append ((xz) + ", " + (yz) + " ; " + "You have selected Region 6")
                        .appendTo('#coordinates');
                        }   
                      });
                    });
                </script>
    <script type="text/javascript">
        $(document).ready(function(){
            $('.hide').click(function(){
            $('.cross').hide();
            });
        });
    </script>

    </head>
    <body
    <div id="container"><img class="WindSh" src="WindShield.png"></div>
    <div>Coordinates x,y: <span id="coordinates"></span></div>
    <input type="button" class="hide" value="hide">

    </body>
</html>

1 个答案:

答案 0 :(得分:0)

所以我要使这个图像x附加在另一个图像y的顶部。图像x应该给出在图像y上附加的坐标。第二,当图像x被追加时,它打开另一个div,在其中显示附加图像x的坐标。在该div中还有一个删除按钮。删除按钮当前删除该行,但我还希望删除按钮删除与该div对应的附加图像。日Thnx