0

0

HTML+CSS+JS 模仿 Win10 亮度调节效果

Guanhui

Guanhui

发布时间:2020-07-18 18:00:40

|

2948人浏览过

|

来源于jb51

转载


HTML+CSS+JS 模仿 Win10 亮度调节效果

HTML+CSS+JS模仿win10亮度调节效果

代码



	
		
		模仿win10的亮度调节
		
	
	
		

1.将各个元素的样子写出来

这里为了方便好观察给body添加了一个背景颜色

立即学习前端免费学习笔记(深入)”;

html

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

效果图

讯飞听见会议
讯飞听见会议

科大讯飞推出的AI智能会议系统

下载

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

这里为了显示遮罩效果把遮罩层的p宽度设小了

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用控制条来控制其透明度达到亮度调节效果

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

推荐教程:《HTML教程

相关文章

HTML速学教程(入门课程)
HTML速学教程(入门课程)

HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!

下载

相关标签:

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

相关专题

更多
css
css

css是层叠样式表,用来表现HTML或XML等文件样式的计算机语言,不仅可以静态地修饰网页,还可以配合各种脚本语言动态地对网页各元素进行格式化。php中文网还为大家带来html的相关下载资源、相关课程以及相关文章等内容,供大家免费下载使用。

500

2023.06.15

css居中
css居中

css居中:1、通过“margin: 0 auto; text-align: center”实现水平居中;2、通过“display:flex”实现水平居中;3、通过“display:table-cell”和“margin-left”实现居中。本专题为大家提供css居中的相关的文章、下载、课程内容,供大家免费下载体验。

261

2023.07.27

css如何插入图片
css如何插入图片

cssCSS是层叠样式表(Cascading Style Sheets)的缩写。它是一种用于描述网页或应用程序外观和样式的标记语言。CSS可以控制网页的字体、颜色、布局、大小、背景、边框等方面,使得网页的外观更加美观和易于阅读。php中文网给大家带来了相关的教程以及文章,欢迎大家前来阅读学习。

731

2023.07.28

css超出显示...
css超出显示...

在CSS中,当文本内容超出容器的宽度或高度时,可以使用省略号来表示被隐藏的文本内容。本专题为大家提供css超出显示...的相关文章,相关教程,供大家免费体验。

534

2023.08.01

css字体颜色
css字体颜色

CSS中,字体颜色可以通过属性color来设置,用于控制文本的前景色,字体颜色在网页设计中起到很重要的作用,具有以下表现作用:1、提升可读性;2、强调重点信息;3、营造氛围和美感;4、用于呈现品牌标识或与品牌形象相符的风格。

748

2023.08.10

什么是css
什么是css

CSS是层叠样式表(Cascading Style Sheets)的缩写,是一种用于描述网页(或其他基于 XML 的文档)样式与布局的标记语言,CSS的作用和意义如下:1、分离样式和内容;2、页面加载速度优化;3、实现响应式设计;4、确保整个网站的风格和样式保持统一。

594

2023.08.10

css三角形怎么写
css三角形怎么写

CSS可以通过多种方式实现三角形形状,本专题为大家提供css三角形怎么写的相关教程,大家可以免费体验。

556

2023.08.21

css设置文字颜色
css设置文字颜色

CSS(层叠样式表)可以用于设置文字颜色,这样做有以下好处和优势:1、增加网页的可视化效果;2、突出显示某些重要的信息或关键字;3、增强品牌识别度;4、提高网页的可访问性;5、引起不同的情感共鸣。

387

2023.08.22

桌面文件位置介绍
桌面文件位置介绍

本专题整合了桌面文件相关教程,阅读专题下面的文章了解更多内容。

0

2025.12.30

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
Bootstrap 5教程
Bootstrap 5教程

共46课时 | 2.7万人学习

AngularJS教程
AngularJS教程

共24课时 | 2.1万人学习

CSS教程
CSS教程

共754课时 | 17.2万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号