day65作业
- 有 红、黄、蓝 三个按钮,以及一个200x200矩形框box,点击不同的按钮,box的颜色会被切换为指定的颜色
<body>
<div id="app">
<p :style="{width:w,height:h,backgroundColor:bg}">{{ msg }}</p>
<button @click="fn('red')">红</button>
<button @click="fn('yellow')">黄</button>
<button @click="fn('blue')">蓝</button>
<button @click="fn('white')">取消</button>
</div>
<script src="js/vue.js"></script>
<script>
new Vue({
el:'#app',
data:{
msg:'box',
w:'200px',
h:'200px',
bg:'red'
},
methods:{
fn(color){
this.bg = color
}
}
})
</script>
</body>
2.有一个200x200矩形框wrap,点击wrap本身,记录点击次数,如果是1次wrap为pink色,2次wrap为green色,3次wrap为cyan色,4次重新回到pink色,依次类推
<body>
<div id="app">
<button :style="{width:w,height:h,backgroundColor:c}" @click="changeColor">{{ wrap }}</button>
<p>点击的次数:{{ num }}</p>
</div>
<script src="js/vue.js"></script>
<script>
new Vue({
el: '#app',
data: {
wrap: '我是wrap框,请点我!',
w:'200px',
h:'200px',
c:'white',
num: 0,
colorArr:['pink','green','cyan'],
},
methods:{
changeColor(){
let n = this.num += 1;
this.c = this.colorArr[n % 3];
}
}
})
</script>
</body>
- 图形初始左红右绿,点击一下后变成上红下绿,再点击变成右红左绿,再点击变成下红上绿,依次类推
<style>
.box {
width: 200px;
height: 200px;
border: 1px solid black;
border-radius: 50%;
overflow: hidden;
position: relative;
}
.b1 {
background-color: red;
position: absolute;
}
.b2 {
background-color: green;
position: absolute;
}
.l {
width: 100px;
height: 200px;
left: 0;
}
.r {
width: 100px;
height: 200px;
right: 0;
}
.t {
width: 200px;
height: 100px;
top: 0;
}
.b {
width: 200px;
height: 100px;
bottom: 0;
}
</style>
<body>
<div id="app">
<div class="box" @click="clickAction">
<div class="b1" :class="c1"></div>
<div class="b2" :class="c2"></div>
</div>
</div>
<script src="js/vue.js"></script>
<script>
let app = new Vue({
el: '#app',
data: {
count: 1,
c1: 'l',
c2: 'r',
c1Arr: ['l', 't', 'r', 'b'],
c2Arr: ['r', 'b', 'l', 't']
},
methods: {
clickAction() {
let n = this.count += 1;
this.c1 = this.c1Arr[n % 4];
this.c2 = this.c2Arr[n % 4];
}
}
});
// 利用定时器自动旋转图像
// setInterval(function () {
// app.clickAction();
// }, 500)
</script>
</body>

浙公网安备 33010602011771号