如何实现“摇一摇”功能
摇一摇需要添加cordova插件:cordova plugin add cordova-plugin-device-motion,获取设备的加速度来实现手机摇动幅度的计算。
框架选择为比较流行的JQuery Mobile
一、html文件代码
- 代码为:
<div data-role="content"> //创建一个容器
<div class="house">
<div id="img"></div>
</div>
<h1 id="heci"></h1>
<div class="cen">
<button id="btstart" data-inline="true">开始</button> //创建一个按钮,data-inline让按钮适应其内容
</div>
</div>
二、css文件代码
- 代码为:
.house{height:260px;background-image:url("img/ma.png");background-repeat:no-repeat;background-position:center center;