您的位置:首页 > Web前端 > JQuery

JQuery 图片拖拽练习

2013-05-09 11:02 302 查看


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

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: