Vue製作測滑動菜單Demo

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
		<title>JavaScript_expression</title>
	</head>
	<style>
		*{
			margin: 0;
			padding: 0;
			box-sizing: border-box;
		}
		.page{
			width: 100vw;
			height: 100vh;
			color: #fff;
			position: fixed;
			background-color: red;
		}
	
	.rMenu{
		width: 50vw;
		height: 100vh;
		position: fixed;
		left: 0;
		top: 0;
		transform: translateX(100vw);
		background: #008000;
		transition: transform 3s;
	}
	.active{
		transform: translateX(50vw);
	}
	</style>
	<body>
		<div id='app'>
			<div class="page">
				<div>
					<button @click="toggleMenu">切換側邊欄</button>
				</div>
			</div>
			<div class="rMenu" :class="{active:isShow}">
				側邊欄
			</div>
		</div>
	</body>
</html>
<script type="text/javascript">
	var app = new Vue({
		el: '#app',
		data: {
			isShow: false
		},
		methods: {
			toggleMenu: function() {
				this.isShow = !this.isShow
			}
		}

	})
</script>

效果:

測滑動

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章