AJAX draggable实现的拖曳效果

来源:互联网 发布:淘宝网店代理靠谱么 编辑:程序博客网 时间:2024/04/30 00:58

<!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>
    <style type="text/css">
    img{width:100px;height:100px;}
    #mydiv{width:500px;height:300px;border:solid 1px red;}
    #mydiv2{width:300px;height:300px;border:solid 1px red;}
    </style>
    <script src="js/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({
                //axis:'y'//规定只能沿y轴拖动
               //containment: '#mydiv2'//规定拖定的区域
                //containment: 'parent'//父容器的别一种写法
                //containment:'#div2'//规定的拖动区域可以不是元素的父容器
               //grid:[10,10]
               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/35x35/12.jpg"/></div>
<div id="#mydiv2">  <input id="Button1" type="button" value="button" />
</div>  
</body>
</html>

原创粉丝点击