濮阳杆衣贸易有限公司

主頁 > 知識庫 > HTML+CSS+JS模仿win10亮度調(diào)節(jié)效果的示例代碼

HTML+CSS+JS模仿win10亮度調(diào)節(jié)效果的示例代碼

熱門標簽:crm外呼系統(tǒng)好不好 電話機器人批發(fā) 電銷外呼線路改不外呼線路 貴陽ai外呼系統(tǒng) 重慶人工智能電銷機器人報價 愛巢地圖標注 強訊外呼系統(tǒng) 智能電銷機器人廣告語 長春極信防封電銷卡公司

HTML+CSS+JS模仿win10亮度調(diào)節(jié)效果

代碼

<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title>模仿win10的亮度調(diào)節(jié)</title>
		<style>
			.control_bar{
				height:200px;
				width:500px;
				border-bottom:3px solid #888888;
				
			}
			.control_bar_cursor{
				height:25px;
				width:8px;
				background: #505151;
				border-radius:5px;
				margin-top:-12.5px;
				position:relative;
				top:0;
				left:0;
			}
			.control_bar_cursor:hover{
				background:white;
			}
			#control_bar_mask{
				margin-top:-203px;
				width:0px;
			}
			.mask{
				position:fixed;
				bottom:0;
				top:0;
				left:0;
				right:0;
				background:black;
				z-index:-1;
			}
		</style>
	</head>
	<body>
		<div class="mask"></div>
		<div class="control_bar"></div>
		<div class="control_bar" style="border-bottom:3px solid #505151;" id="control_bar_mask"></div>
		<div class="control_bar_cursor"></div>
	</body>
	<script>
		window.onload = function(){
			var control_bar = document.getElementsByClassName("control_bar")[0];
			var control_bar_mask = document.getElementById("control_bar_mask");
			var control_bar_cursor = document.getElementsByClassName("control_bar_cursor")[0];
			var def_left = control_bar_cursor.offsetLeft;
			var mask = document.getElementsByClassName("mask")[0];
			document.body.onmousedown = function(){
				window.onmousemove = function(){
					var cursor_X = event.clientX;
					var cursor_Y = event.clientY;
					if(cursor_X < def_left){
						control_bar_cursor.style.left = 0;
					}else if(cursor_X > control_bar.offsetWidth + def_left){
						control_bar_cursor.style.left = control_bar.offsetWidth;
					}else{
						control_bar_cursor.style.left = cursor_X - def_left + "px";
					}
					//亮度比
					var proportion = parseInt(control_bar_cursor.offsetLeft - def_left) / parseInt(control_bar.offsetWidth - 1);
					control_bar_mask.style.width = proportion * control_bar.offsetWidth + "px";
					mask.style.opacity = 1 - proportion;
					};
				window.onmouseup = function(){
					window.onmousemove = null;
				};
			};
		};
	</script>
</html>

1.將各個元素的樣子寫出來

​這里為了方便好觀察給body添加了一個背景顏色

html

<div class="control_bar">
</div>
<div class="control_bar" style="border-bottom:3px solid #505151;"  
id="control_bar_mask>
</div>
<div class="control_bar_cursor">
</div>

css

body{
    background:back;
}
.control_bar{
    height:200px;
    width:500px;
    border-bottom:3px solid #888888;
}
.control_bar_cursor{
    height:25px;
    width:8px;
    background: #505151;
    border-radius:5px;
}

效果圖

2. 將各個元素疊到一起

css

body{
    background:black;
}
.control_bar{
    height:200px;
    width:500px;
    border-bottom:3px solid #888888;

}
.control_bar_cursor{
    height:25px;
    width:8px;
    background: #505151;
    border-radius:5px;
    margin-top:-12.5px;
    position:relative;
    top:0;
    left:0;
}
.control_bar_cursor:hover{
    background:white;
}
#control_bar_mask{
    margin-top:-203px;
    width:100px;
}

這里為了顯示遮罩效果把遮罩層的div寬度設(shè)小了

3. 添加js

js

window.onload = function(){
    var control_bar = document.getElementsByClassName("control_bar")[0];
    var control_bar_mask = document.getElementById("control_bar_mask");
    var control_bar_cursor = document.getElementsByClassName("control_bar_cursor")[0];
    var def_left = control_bar_cursor.offsetLeft;
    document.body.onmousedown = function(){
        window.onmousemove = function(){
            var cursor_X = event.clientX;
            var cursor_Y = event.clientY;
            if(cursor_X < def_left){
                control_bar_cursor.style.left = 0;
            }else if(cursor_X > control_bar.offsetWidth + def_left){
                control_bar_cursor.style.left = control_bar.offsetWidth;
            }else{
                control_bar_cursor.style.left = cursor_X - def_left + "px";
            }
            var proportion = parseInt(control_bar_cursor.offsetLeft - def_left) / parseInt(control_bar.offsetWidth - 1);
            control_bar_mask.style.width = proportion * control_bar.offsetWidth + "px";
        };
        window.onmouseup = function(){
            window.onmousemove = null;
        };
    };
};

4. 添加一個mask用控制條來控制其透明度達到亮度調(diào)節(jié)效果

<div class="mask"></div>
.mask{
    position:fixed;
    bottom:0;
    top:0;
    left:0;
    right:0;
    background:black;
    z-index:-1;
}
window.onload = function(){
    var control_bar = document.getElementsByClassName("control_bar")[0];
    var control_bar_mask = document.getElementById("control_bar_mask");
    var control_bar_cursor = document.getElementsByClassName("control_bar_cursor")[0];
    var def_left = control_bar_cursor.offsetLeft;
    var mask = document.getElementsByClassName("mask")[0];
    document.body.onmousedown = function(){
        window.onmousemove = function(){
            var cursor_X = event.clientX;
            var cursor_Y = event.clientY;
            if(cursor_X < def_left){
                control_bar_cursor.style.left = 0;
            }else if(cursor_X > control_bar.offsetWidth + def_left){
                control_bar_cursor.style.left = control_bar.offsetWidth;
            }else{
                control_bar_cursor.style.left = cursor_X - def_left + "px";
            }
            //亮度比
            var proportion = parseInt(control_bar_cursor.offsetLeft - def_left) / parseInt(control_bar.offsetWidth - 1);
            control_bar_mask.style.width = proportion * control_bar.offsetWidth + "px";
            mask.style.opacity = 1 - proportion;
        };
        window.onmouseup = function(){
            window.onmousemove = null;
        };
    };
};

總結(jié)

到此這篇關(guān)于HTML+CSS+JS模仿win10亮度調(diào)節(jié)效果的示例代碼的文章就介紹到這了,更多相關(guān)html css win10 亮度調(diào)節(jié)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持腳本之家!

標簽:保定 陜西 上海 廣安 清遠 內(nèi)蒙古 吳忠 山南

巨人網(wǎng)絡(luò)通訊聲明:本文標題《HTML+CSS+JS模仿win10亮度調(diào)節(jié)效果的示例代碼》,本文關(guān)鍵詞  HTML+CSS+JS,模仿,win10,亮度,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《HTML+CSS+JS模仿win10亮度調(diào)節(jié)效果的示例代碼》相關(guān)的同類信息!
  • 本頁收集關(guān)于HTML+CSS+JS模仿win10亮度調(diào)節(jié)效果的示例代碼的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    启东市| 建昌县| 建湖县| 朝阳市| 潼南县| 博兴县| 大田县| 广宁县| 射阳县| 上高县| 沁阳市| 营口市| 漳州市| 北票市| 丰顺县| 乐昌市| 延寿县| 土默特右旗| 宣武区| 新竹县| 东明县| 康定县| 原阳县| 津市市| 开封市| 贵港市| 凌海市| 辽阳县| 潞西市| 鄱阳县| 建平县| 军事| 巫山县| 象山县| 北京市| 潮安县| 荥阳市| 和平县| 四平市| 阿荣旗| 丽水市|