Matter.js如何做一个夹子?

JavaScript012

Matter.js如何做一个夹子?,第1张

引入Body模块

var Body=Matter.Body

旋转物体

Events.on(mouseConstraint, startdrag, function(e){

Body.rotate(e.body,Math.PI/4)

$(rotate)[0].play()

})

1

2

3

4

点击物体时,将其旋转45度。此方法中,角度的单位为弧度

设置物体速度

$(start).click(function(){

Body.setVelocity(bodyA,{x:0,y:10})

})

1

2

3

点击特定dom按钮时,设置指定物体的速度

需要准备的材料分别有:电脑、html编辑器、浏览器。

1、首先,打开html编辑器,新建html文件,例如:index.html。

2、在index.html中的<script>标签,输入js代码:window.external.addFavorite(location.href, '我的网站')。

3、浏览器运行index.html页面,此时会弹出添加到收藏夹的面板,点击完成即可。