JQuery实现拖动删除效果

来源:互联网 发布:百度大数据 编辑:程序博客网 时间:2024/06/04 19:36

<title></title>
    <style type="text/css">
        #mydiv
        {
            width: 900px;
            background-color: #444;
        }
        img
        {
            width: 200px;
            height: 200px;
        }
        ul
        {
            list-style-type: none;
        }
        ul li
        {
            display: inline;
        }
    </style>
    <script src="Jquery1.7.js" type="text/javascript"></script>
    <script src="拖动js/jquery.ui.core.js" type="text/javascript"></script>
    <script src="拖动js/jquery.ui.widget.js" type="text/javascript"></script>
    <script src="拖动js/jquery.ui.mouse.js" type="text/javascript"></script>
    <script src="拖动js/jquery.ui.draggable.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            //            $('img').draggable({
            //                stop: function () {
            //                    if ($(this).offset().top > 200 || $(this).offset().left > 900) {
            //                        $(this).remove();
            //                    }
            //                    else {
            //                        revert: true;
            //                    }
            //                },
            //                revert: false
            //            });
            var c;
            $('img').draggable({
                start: function () {
                    //                    a = $(this).offset().top;
                    //                    b = $(this).offset().left;
                    $(this).css('z-index',);
                },
                drag: function () {
                    if (c) {
                        $(this).mouseout(function () {
                            c = false;
                            $(this).remove();
                        })
                    }

                    if ($(this).offset().top > ($(this).parent().parent().parent().offset().top + 200) || $(this).offset().left > 900) {
                        c = true;
                    }
                    //$('#label1').text($(this).offset().left + ',' + $(this).offset().top + ':' + $(this).parent().offset().top);
                },
                revert: true
            })

        })
    </script>
</head>
<body>
    <div id="mydiv">
        <ul>
            <li>
                <img src="images/2.jpg" /></li>
            <li>
                <img src="images/3.jpg" /></li>
            <li>
                <img src="images/4.jpg" /></li>
            <li>
                <img src="images/5.jpg" /></li>
        </ul>
    </div>
</body>

原创粉丝点击