加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

AJAX draggable实现的拖曳效果

发布时间:2020-12-15 20:57:02 所属栏目:百科 来源:网络整理
导读:!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{

<!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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读