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

HTML模仿win10亮度调节效果相关推荐

  1. html中图片亮度调节,HTML+CSS+JS 模仿 Win10 亮度调节效果

    HTML+CSS+JS模仿win10亮度调节效果 代码 模仿win10的亮度调节 .control_bar{ height:200px; width:500px; border-bottom:3px ...

  2. html的window效果,HTML+CSS+JS模仿win10亮度调节效果

    HTML+CSS+JS模仿win10亮度调节效果 代码 模仿win10的亮度调节 .control_bar{ height:200px; width:500px; border-bottom:3px ...

  3. html中亮度怎么写,HTML+CSS+JS模仿win10亮度调节效果的示例代码

    HTML+CSS+JS模仿win10亮度调节效果 代码 模仿win10的亮度调节 .control_bar{ height:200px; width:500px; border-bottom:3px ...

  4. 惠普战66键盘win10亮度调节快捷键失灵的解决办法

    问题可能原因:在外部硬件没有损坏的情况下,最大的可能就是驱动程序出了问题. 解决办法:1.首先让我们看一下win10中有哪些常见的屏幕亮度调节的方法 <显示设置>/ 如果上述方法不可行可以 ...

  5. win10亮度调节消失的解决方法

    1.起因: 某一天起,win10系统的亮度调节的功能突然消失了,在网上试了很多办法,也去微软的反馈页面上寻找办法,最后找到的原因是黑屏驱动,teamview与向日葵都通过自己的黑屏驱动,提供远控时黑屏 ...

  6. Win10亮度调节无效

    Win10调节亮度无效 前言 曾经在Win7电脑上,我曾经误按调节亮度的F11按键,亮度直接变为最低,而F12亮度却增加不了,在重启看到Lenovo开机时狂按F12则会恢复正常.如今的Win10系统却 ...

  7. win10亮度调节变为灰色无法调节

    右键在显示适配器中卸载这两个东西,然后重启,发现好起来了 可以正常调节了

  8. OpenGL 亮度调节

    目录 一.OpenGL 亮度调节效果演示 1.IOS 演示效果 2.Windows OpenGL ES 演示效果 3.Windows OpenGL 演示效果 二.OpenGL 亮度调节源码下载 1.I ...

  9. win10计算机屏幕暗怎么办,Win10系统调节不了屏幕亮度怎么办

    Win10系统调节不了屏幕亮度怎么办?有win10用户反馈在升级系统后,发现win10屏幕亮度调节不了,导致有些电脑屏幕太亮刺眼,有些电脑屏幕亮度太低,看屏幕都费劲,这是什么原因呢?下面先介绍几种出现 ...

最新文章

  1. python栈溢出_Python栈溢出【新手必学】
  2. 不允许 ASSIGNMENT 语句中包含 FOR XML 子句。
  3. MySQL添加字段和修改字段的方法
  4. 51nod 1158 全是1的最大子矩阵(单调栈 ,o(n*m))
  5. cPanel附加域名出现Error from park wrapper: 使用带以下 IP 的命名服务器:
  6. J2ME开发模拟器KEmulator简介及使用
  7. Redhat使用yum install时提示This system is not registered with an entitlement server 的解决办法
  8. 数字图像处理王慧琴课后答案_数字图像处理课后题答案
  9. java科学计数法的基本使用与如何看科学计数法
  10. 论文笔记 PCL: Proposal Cluster Learning for Weakly Supervised Object Detection - TPAMI 2018
  11. 前端-HTML基础入门
  12. 超级无敌小小迷你宝宝小可爱大仙女芊老婆~
  13. python输入第十个斐波那契数列,0,1,1,2,3,5,8,13,21,34
  14. 数学建模推国一最终省一经验总结
  15. Ai 文字正确描边 文字描边
  16. python中如何上下标
  17. C++类成员函数返回对象及返回引用
  18. python英语字典程序-python制作英文学习字典案列
  19. LightGBM分类实战
  20. npm-shrinkwrap锁定依赖

热门文章

  1. iOS 图片 绘制梯形 背景图屠屏
  2. 第二型曲面积分的定义
  3. 基于Java+SSM+Vue农家乐管理系统(住宿-美食-活动)设计与实现
  4. 窗口管理工具:HazeOver for Mac
  5. 数列极限四则运算误区
  6. 项目——3——lnmp-gitlab-jenkins-ansible
  7. ireport怎么实现总计和小计?
  8. DIY服务器raid硬盘检测,DIY存储服务器技术篇——硬盘RAID选用(3)
  9. 干货!Labeling Trick: 一个图神经网络多节点表示学习理论
  10. 容器亲和、反亲和、污点、容忍以及驱逐的介绍