vue之综合Demo:打沙袋

时间:2021-12-12 18:51:38

demo7.html

 <!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml" xmlns:v-html="http://www.w3.org/1999/xhtml"
xmlns:v-on="http://www.w3.org/1999/xhtml" xmlns:v="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>Vue Demo</title>
<!--自选版本-->
<!--<script src="https://cdn.jsdelivr.net/npm/vue@2.5.21/dist/vue.js"></script>-->
<!-- 开发环境版本,包含了有帮助的命令行警告 -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<!-- 生产环境版本,优化了尺寸和速度 -->
<!--<script src="https://cdn.jsdelivr.net/npm/vue"></script>-->
<link href="style.css" rel="stylesheet">
</head>
<body>
<div id="app">
<h2>综合Demo</h2>
<!--图片-->
<div id="bag" v-bind:class="{burst:ended}"></div> <!--进度情况-->
<div id="bag-health">
<div v-bind:style="{width: health + '%' }">
</div>
</div> <h3 v-show="ended" align="center">
沙袋被你打坏了!
</h3>
<!--控制按钮-->
<div id="controls">
<button v-on:click="punch" v-show="!ended">使劲敲打</button>
<button v-on:click="restart">重新开始</button>
</div> </div>
<script src="app.js"></script>
</body>
</html>

app.js

var app = new Vue({
el: '#app',
data: {
health: 100,
ended: false,
},
methods: {
punch: function () {
this.health -= 25;
if (this.health <= 0) {
this.ended = true;
// alert("被你打坏了!你真棒!")
}
},
restart: function () {
this.health = 100;
this.ended = false;
}
}, computed: {}
})

style.css

 #bag {
width: 200px;
height: 500px;
margin: 0 auto;
background: url("pic/sha1.png") center no-repeat;
background-size: 80%;
} #bag.burst {
background-image: url("pic/sha2.png");
} #bag-health {
width: 200px;
border: 2px #000 solid;
margin: 0 auto 20px auto;
} #bag-health div {
height: 20px;
background: greenyellow;
} #controls {
width: 200px;
margin: 0 auto;
} #controls button {
margin-left: 20px;
}

截图:

vue之综合Demo:打沙袋

vue之综合Demo:打沙袋