html+css:電池電量百分比效果圖

效果圖:

在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述

代碼

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<style>
			.container {
				height: 200px;
				width: 120px;
				position: relative;
				border: 1px solid pink;
				box-sizing: content-box;
				border-top: none;
			}
			
			.box {
				width: 120px;
				background-color: pink;
				position: absolute;
				bottom: 0;
				left: 0;
				right: 0;
			}
			
			.rela {
				position: relative;
				width: 100%;
				height: 100%;
			}
			
			.leftCon {
				width: 41px;
				height: 19px;
				position: absolute;
				left: -1px;
				top: 0;
				background-color: white;
				border-right: 1px solid pink;
				border-bottom: 1px solid pink;
				border-left: 1px solid white;
				border-top: 1px solid white;
			}
			
			.rightCon {
				border-right: 1px solid white;
				border-top: 1px solid white;
				width: 41px;
				height: 19px;
				position: absolute;
				right: -1px;
				top: 0;
				background-color: white;
				border-left: 1px solid pink;
				border-bottom: 1px solid pink;
				border-right: 1px solid white;
				border-top: 1px solid white;
			}
			
			.line {
				width: 40px;
				height: 1px;
				background-color: pink;
				position: absolute;
				top: 0;
				left: 40px;
			}
		</style>
		// 引入jquery
		<script src="jquery-3.4.1.min.js"></script>
	</head>

	<body>
		<div style="margin-bottom: 20px;">
			<span>
				請輸入電池電量百分比:0-100範圍
			</span> <input class="inputVal" value="" />
		</div>
		<div class="container">
			<div class="box">
			</div>
			<div class="rela">
				<div class="line">
				</div>
				<div class="leftCon">
				</div>
				<div class="rightCon">
				</div>
			</div>
		</div>
		<script>
			$('.inputVal').change(function() {
				$('.box').css({
					height: $('.inputVal').val() * 2 + 'px'
				})
			})
		</script>

	</body>

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