欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

  發(fā)布時間:2020-06-04 15:39:18   作者: 南小樹   我要評論
這篇文章主要介紹了HTML+CSS+JS模仿win10亮度調(diào)節(jié)效果的示例代碼,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

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用控制條來控制其透明度達(dá)到亮度調(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)文章,希望大家以后多多支持腳本之家!

相關(guān)文章

  • HTML 表格詳解(簡單易懂較詳細(xì))

    HTML表格用于在網(wǎng)頁上展示數(shù)據(jù),通過標(biāo)簽及其相關(guān)標(biāo)簽來創(chuàng)建,表格由行和列組成,每一行包含一個或多個單元格,單元格可以包含文本、圖像、鏈接等元素,本文將詳細(xì)介紹HTML表格
    2025-03-12
  • 禁止HTML頁面滾動的操作方法

    本文介紹了三種禁止HTML頁面滾動的方法:通過CSS的overflow屬性、使用JavaScript的滾動事件監(jiān)聽器以及使用CSS的position:fixed屬性,每種方法都有其適用場景和優(yōu)缺點,感興
    2025-02-24
  • 使用HTML和CSS實現(xiàn)文字鏤空效果的代碼示例

    在 Web 開發(fā)中,文本的視覺效果是提升用戶體驗的重要因素之一,通過 CSS 技巧,我們可以創(chuàng)造出許多獨特的效果,例如文字鏤空效果,本文將帶你一步一步實現(xiàn)一個簡單的文字鏤空
    2024-11-17
  • Html去除a標(biāo)簽的默認(rèn)樣式的操作代碼

    在Html中,a標(biāo)簽?zāi)J(rèn)的超鏈接樣式是藍(lán)色字體配下劃線,這可能不滿足所有設(shè)計需求,如需去除這些默認(rèn)樣式,可以通過CSS來實現(xiàn),本文給大家介紹Html去除a標(biāo)簽的默認(rèn)樣式的操作代碼
    2024-09-25
  • HTML文本域如何設(shè)置為禁止用戶手動拖動

    在HTML中,可以通過設(shè)置CSS的resize屬性為none,來禁止用戶手動拖動文本域(textarea)的大小,這種方法簡單有效,適用于大多數(shù)現(xiàn)代瀏覽器,但需要在老舊瀏覽器中進(jìn)行測試以確保
    2024-09-25
  • 如何通過HTML/CSS 實現(xiàn)各類進(jìn)度條的功能

    本文詳細(xì)介紹了如何利用HTML和CSS實現(xiàn)多種風(fēng)格的進(jìn)度條,包括基礎(chǔ)的水平進(jìn)度條、環(huán)形進(jìn)度條以及球形進(jìn)度條等,還探討了如何通過動畫增強視覺效果,內(nèi)容涵蓋了使用HTML原生標(biāo)簽
    2024-09-19
  • HTML中Canvas關(guān)鍵知識點總結(jié)

    Canvas 提供了一套強大的 2D 繪圖 API,適用于各種圖形繪制、圖像處理和動畫制作,可以幫助你創(chuàng)建復(fù)雜且高效的網(wǎng)頁圖形應(yīng)用,這篇文章主要介紹了HTML中Canvas關(guān)鍵知識點總結(jié)
    2024-06-03
  • html table+css實現(xiàn)可編輯表格的示例代碼

    本文主要介紹了html table+css實現(xiàn)可編輯表格的示例代碼,主要使用HTML5的contenteditable屬性,文中通過示例代碼介紹的非常詳細(xì),需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)
    2024-03-06
  • HTML中使用Flex布局實現(xiàn)雙行夾批效果

    本文主要介紹了HTML中使用Flex布局實現(xiàn)雙行夾批效果,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)
    2024-02-22
  • HTML+CSS實現(xiàn)炫酷登錄切換的項目實踐

    在網(wǎng)站開發(fā)中,登錄頁面是必不可少的一部分,本文就來介紹一下HTML+CSS實現(xiàn)登錄切換,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需
    2024-02-02

最新評論