小球碰撞-获取坐标
来源:互联网 发布:淘宝的观复博物馆 编辑:程序博客网 时间:2024/06/16 19:43
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
div{
width:200px;
height: 200px;
background-color: pink;
/*margin-left: 100px;
margin-top: 100px;*/
border-radius: 100px;
}
p{
width: 100px;
height: 100px;
background-color: yellow;
position: absolute;
left: 500px;
top:200px;
border-radius: 50px;
text-align: center;
line-height: 100px;
}
</style>
</head>
<body>
<div>
</div>
<p></p>
</body>
<script src="js/jquery-3.2.1.min.js" ></script>
<script type="text/javascript">
//坐标点相对于整个文档边缘
$('div').on('mousedown',function(event){
// console.log(event.clientX);//x方向坐标
//console.log(event.clientY);//y方向坐标
// $('div').eq(0).css({'marginTop':''+event.clientX+''});
// $('div').eq(0).css({'marginLeft':''+event.clientY+''});
//鼠标点距离 拖拽块边缘的距离
var Dx=event.clientX-($('div').offset().left);
var Dy=event.clientY-($('div').offset().top);
$('div').on('mousemove',function(event){
var _left=(event.clientX-Dx);
var _top=(event.clientY-Dy);
$('div').css({'marginTop':_top+'px','marginLeft':_left+'px'});
if($('p').offset().left<=$('div').width()+$('div').offset().left &&
$('div').offset().left<=$('p').width()+$('p').offset().left &&
$('p').offset().top<=$('div').height()+$('div').offset().top&&
$('div').offset().top<=$('p').height()+$('p').offset().top
){
$('p').css({'backgroundColor':'red'});
$('p').html('撞到我了');
}else{
$('p').css({'backgroundColor':'yellow'});
$('p').html('来撞我啊');
}
AJAX
});
});
//鼠标抬起移除事件
$(document).on('mouseup',function(){
$('div').off('mousemove');
});
</script>
</html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
div{
width:200px;
height: 200px;
background-color: pink;
/*margin-left: 100px;
margin-top: 100px;*/
border-radius: 100px;
}
p{
width: 100px;
height: 100px;
background-color: yellow;
position: absolute;
left: 500px;
top:200px;
border-radius: 50px;
text-align: center;
line-height: 100px;
}
</style>
</head>
<body>
<div>
</div>
<p></p>
</body>
<script src="js/jquery-3.2.1.min.js" ></script>
<script type="text/javascript">
//坐标点相对于整个文档边缘
$('div').on('mousedown',function(event){
// console.log(event.clientX);//x方向坐标
//console.log(event.clientY);//y方向坐标
// $('div').eq(0).css({'marginTop':''+event.clientX+''});
// $('div').eq(0).css({'marginLeft':''+event.clientY+''});
//鼠标点距离 拖拽块边缘的距离
var Dx=event.clientX-($('div').offset().left);
var Dy=event.clientY-($('div').offset().top);
$('div').on('mousemove',function(event){
var _left=(event.clientX-Dx);
var _top=(event.clientY-Dy);
$('div').css({'marginTop':_top+'px','marginLeft':_left+'px'});
if($('p').offset().left<=$('div').width()+$('div').offset().left &&
$('div').offset().left<=$('p').width()+$('p').offset().left &&
$('p').offset().top<=$('div').height()+$('div').offset().top&&
$('div').offset().top<=$('p').height()+$('p').offset().top
){
$('p').css({'backgroundColor':'red'});
$('p').html('撞到我了');
}else{
$('p').css({'backgroundColor':'yellow'});
$('p').html('来撞我啊');
}
AJAX
});
});
//鼠标抬起移除事件
$(document).on('mouseup',function(){
$('div').off('mousemove');
});
</script>
</html>
阅读全文
0 0
- 小球碰撞-获取坐标
- 碰撞的小球
- JBox2D学习 - 小球碰撞
- HTML5+Javascript 小球碰撞
- HTML5小球物理碰撞
- java小球弹性碰撞
- flash小球碰撞
- Java版小球碰撞
- Java版小球碰撞
- 碰撞的小球 HTML5
- java碰撞小球
- 小球定时碰撞
- 【HTML5】碰撞的小球
- 【HTML5】SVG小球碰撞
- javaScript实现小球碰撞
- BouncingBallView 碰撞的小球
- javascript 小球碰撞
- BouncingBallView 碰撞的小球
- 操作系统:CPU调度
- 1072. Gas Station (30)
- 【jzoj5347】【NOIP2017提高A组模拟9.5】【遥远的金字塔】【斜率优化动态规划】
- 关于<s:action executeResult="true">死循环
- 2017前端面试题及答案总结(一)
- 小球碰撞-获取坐标
- Boost 学习笔记--->字符串&文本处理
- zigzag-conversion
- 黑科技新添成员, 小米mix5再次创新, 但这些真的只是黑科技的全部吗?
- The kth great number (优先队列)
- Jquery选择器总结一
- 上传图片时button按钮隐藏,用做好的样式
- JSP基础知识(request和response以及页面转发和重定向)
- scroll属性