当前位置:编程学习 > JAVA >>

jQuery拖到效果

  <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.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>
 
补充:web前端 , JavaScript ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,