拖拽删除-jq插件

21 篇文章 0 订阅
7 篇文章 0 订阅

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title></title>
      <script src="Jquery1.7.js" type="text/javascript"></script>
      <script src="tdtp_js/jquery.ui.core.js" type="text/javascript"></script>
      <script src="tdtp_js/jquery.ui.widget.js" type="text/javascript"></script>
      <script src="tdtp_js/jquery.ui.mouse.js" type="text/javascript"></script>
      <script src="tdtp_js/jquery.ui.draggable.js" type="text/javascript"></script>
    <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 type="text/javascript">
        $(function () {
            var a;
            var b;
            $("img").draggable({
                stop: function () {
                    var left = $(this).offset().left;
                    var top = $(this).offset().top;
                    //alert(left + "," + top);
                    //alert($("#mydiv").width());
                    if (left > $("#mydiv").width() + $("#mydiv").offset().left) {
                        $(this).hide(1000);
                        //$(this).parent().remove();
                    }
                    else if (top > $("#mydiv").height() + $("#mydiv").offset().top) {
                        $(this).hide(1000);
                        //$(this).parent().remove();
                    }
                    else {
                        $(this).offset({left:a,top:b});
                    }
                },

                start: function () {
                    a = $(this).offset().left;
                    b = $(this).offset().top;
                }

            })
            $("#Button1").click(function () {
                $("img").show(1500);
              
            })
        })
    </script>
</head>
<body>
    <input id="Button1" type="button" value="button" />
<div id="mydiv">
<ul>
<li><img src="NFLightBox/photos/image1.jpg" /></li>
<li><img src="NFLightBox/photos/image2.jpg" /></li>
<li><img src="NFLightBox/photos/image3.jpg" /></li>
<li><img src="NFLightBox/photos/image4.jpg" /></li>
</ul>
</div>
</body>
</html>


老师笔记

姚宏波 09:21:51 (多人发送)
  <head>
    <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>
</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>
姚宏波 09:24:52 (多人发送)
  <head>
    <title></title>
    <style type="text/css">
        img
        {
            width: 100px;
            height: 100px;
        }
        #mydiv
        {
            width: 500px;
            height: 300px;
            border: solid 1px red;
        }
        #mydiv2
        {
            width: 500px;
            height: 300px;
            border: solid 1px red;
        }
    </style>
    <script src="js/Jquery1.7.js" type="text/javascript"></script>
    <!-- <script src="js/jquery-ui-1.8.18.custom.min.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({
                //axis:'y'//规定只能沿y轴拖动
                //containment: '#mydiv' //规定拖动的区域
                //containment: 'parent' //父容器的另一种写法
                //containment: '#mydiv2' //规定的拖动区域可以不是元素的父容器
                //grid:[50,50]
                opacity: 0.3, //设置拖动时的透明度
                //revert: true,
                start: function () {
                    $('#mydiv2').text('开始移动了');
                },
                stop: function () {
                    $('#mydiv2').text('停了');
                },
                drag: function () {
                    //$('#mydiv2').text('一直在努力');
                    $('#mydiv2').text($('img').offset().left + "," + $('img').offset().top);
                }
            });
            //设置一个元素的距离浏览器左边缘和上边缘的距离(横坐标和纵坐标)
            $('#Button1').click(function () {
                $('img').offset({
                    left: 200,
                    top: 200
                });
            })
        })
    </script>
</head>
<body>
    <div id="mydiv">
        <img src="images/2.jpg" /></div>
    <div id="mydiv2">
        <input id="Button1" type="button" value="button" />
    </div>
</body>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值