HTML+CSS+JS模仿win10亮度調節效果

来源:https://www.cnblogs.com/nanke33/archive/2020/06/04/13043489.html
-Advertisement-
Play Games

HTML+CSS+JS模仿win10亮度調節效果 代碼 <!doctype html> <html> <head> <meta charset="utf-8"> <title>模仿win10的亮度調節</title> <style> .control_bar{ height:200px; width ...


HTML+CSS+JS模仿win10亮度調節效果

代碼

<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title>模仿win10的亮度調節</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寬度設小了

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用控制條來控制其透明度達到亮度調節效果

    <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;
            };
        };
    };
    

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • pyetl是一個純python開發的ETL框架, 相比sqoop, datax 之類的ETL工具,pyetl可以對每個欄位添加udf函數,使得數據轉換過程更加靈活,相比專業ETL工具pyetl更輕量,純python代碼操作,更加符合開發人員習慣 安裝 pip3 install pyetl 使用示例 ...
  • 1. 前言 之前寫過一篇博客,講解的是Redis的5種數據結構及其常用命令,當時有讀者評論,說希望瞭解下這5種數據結構各自的使用場景,不過一直也沒來得及寫。 碰巧,在3月份找工作面試時,有個面試官先問了我Redis有哪幾種數據結構,在我講完後,面試官又問了我以下問題: 如何用Redis實現微信步數排 ...
  • 打開虛擬機進入linux系統 進入Hadoop目錄下 多用tab鍵 它可以自動補齊命令 1. 啟動Hadoop集群 start-all.sh 等價於 start-dfs.sh 和 start-yarn.sh 2. 關閉Hadoop集群 stop-all.sh 3. 查看啟動的服務進程 jps 4. ...
  • 什麼叫大數據,“大”,說的並不僅是數據的“多”!不能用數據到了多少TB ,多少PB 來說。 對於大數據,可以用四個詞來表示:大量,多樣,實時,不確定。 也就是數據的量龐大,數據的種類繁雜多樣話,數據的變化飛快,數據的真假存疑。 大量:這個大家都知道,想百度,淘寶,騰訊,Facebook,Twitte ...
  • 今天和大家分享一下,iOS開發3-5年應該掌握的技能。 大大小小參加過不下30+公司的面試,其中不乏BAT、TMD等一線互聯網公司,總結一下,發現大廠招聘都有一個共性。 對技術的要求很全面,有些開發者認為iOS掌握了基礎的UI、網路、記憶體、多線程等等就夠了,其實要想更好的應付iOS的面試,這些是遠遠 ...
  • 1.先說現狀 現在國內公司開全新項目,Swift 已經占壓倒性優勢了。 很多以前是 OC 的項目也轉向 OC/Swift 混編了。 但是也有對包大小非常敏感的項目,還是純 OC 開發。不少公司剛剛擺脫 MRC 不久,業務壓力大,歷史包袱重,沒有時間推進新技術。 2. 對比一下 OC 和 Swift ...
  • 下麵說一下我的感受吧 自學web前端8個月,我是怎樣拿下7K薪資的?自學兩個字,說起來很輕鬆,但真正做起來那真是絕非易事,說實話,在我收到HR發來的offer那一刻,眼淚差點掉下來,這個過程中吃的這些苦,真的只有自己才能知道,在自學的時候經常會碰到一些技術方面的問題,找不到老師教,只能去群里哪裡找大 ...
  • 結合個人經歷總結的前端入門方法,總結從零基礎到具備前基本技能的道路,學習方法,資料,由於能力有限,不能保證面面俱到,知識作為入門參考,面向初學者,讓初學者少走彎路。 互聯網的快速發展和激烈競爭,用戶體驗成為一個重要的關註點,導致專業前端工程師成為熱門職業,各大公司對前端工程師的需求量都很大,要求也越 ...
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...