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

代码

模仿win10的亮度调节

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

}

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;

};

};

};

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

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

html

id="control_bar_mask>

cssbody{

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. 将各个元素叠到一起

cssbody{

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

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

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+CSS+JS 模仿 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模仿win10亮度调节效果

    HTML+CSS+JS模仿win10亮度调节效果 代码 <!doctype html> <html><head><meta charset="utf ...

  4. JAVA中解决Filter过滤掉css,js,图片文件等问题

    JAVA中解决Filter过滤掉css,js,图片文件等问题 参考文章: (1)JAVA中解决Filter过滤掉css,js,图片文件等问题 (2)https://www.cnblogs.com/er ...

  5. html+css+js实现自动敲文字效果

    html+css+js实现自动敲文字效果 简介:本文是一个前端案例的讲解,关于如何用html+css+js制作出逐渐显示出文字的效果,这个效果可以帮助大家在新人面前装一波. 效果展示 效果就是这个样子 ...

  6. css中图片整合的使用,CSS Sprites:图片整合技术详细案例

    CSS Sprites 的目的就是通过整合图片,减少对服务器的请求数量,从而加快页面加载速度.介绍了CSS Sprites技术的实现方法,优点和缺点.最后通过实例CSS Sprites技术制作导航栏演 ...

  7. css让图片显示圆角 纯CSS绘制漂亮的圆形图案效果

    css让图片显示圆角 样式: border-radius:5px 15px 20px 25px;顺序依次是上右下左 纯CSS绘制漂亮的圆形图案效果 .circle { border-radius: 5 ...

  8. eclipse中添加aptana插件(html.css.js自动提示)

    一.关于aptana aptana是一款很不错的插件,本人主要用于安装此类插件,在eclipse中用于编辑javascript代码,html代码,和css代码的,因为其有自动纠错功能,当然安装后的问题 ...

  9. 怎样在html中插入广告,用div+css+js在文章中间插入广告

    js如下,根据实际情况进行细节调整/// 正文画中画广告 var curUrl = window.location.href; var AdTxt=' try{ var contAd = docume ...

最新文章

  1. 前置体验,才是打动用户的神器
  2. 基于JWT的Token认证机制实现
  3. 操作系统 实验3【动态分区存储管理】
  4. 润乾报表列太多导致渲染速度慢_报表自动化: 如何选择可视化大屏开发利器
  5. java 生成缩略图类_JAVA生成【缩略图】方法
  6. 腾讯砸1亿斗地主欢乐豆签约前《英雄联盟》电竞职业选手Uzi
  7. 微信内测新功能:公众号们脖子一凉...
  8. mysql源码启动_mysql源码分析-启动过程
  9. php是什么电器元件,第三代计算机采用的主要电子元器件是什么
  10. Android开发-数据回传
  11. java ee 酒店管理系统,基于jsp的小型酒店管理系统-JavaEE实现小型酒店管理系统 - java项目源码...
  12. 用Axure做页面原型设计
  13. 蚁群算法原理及python实现
  14. 谷歌内核浏览器无法下载文件的解决方法
  15. 系统性能统计(CPU占用率,内存占用率,系统平均负载)
  16. 【乱七八糟的笔记】——前缀树
  17. 【Bioinfo Blog 011】【R Code 008】——功能富集分析
  18. 单调有界定理适用于函数吗_用极限定义证明一些极限的性质定理
  19. iPhone X(iOS 14.6)在Win 10上使用iRemoval PRO v5.1.2进行越狱
  20. java有趣的技术分享ppt,java面试数据结构与算法高频考

热门文章

  1. Spring 让 LOB 数据操作变得简单易行
  2. 苹果历代产品中的8大亮点设计(上)
  3. 用户获取pppd拨号状态_iPhone手机隐藏的拨号键代码,原来还能这么用,幸好钱没白花...
  4. 从零双排java之转换流
  5. 太原市山大附中2021年高考成绩查询,2021年太原高考状元名单公布,太原高考状元学校资料及最高分...
  6. 怎样利用python做一个软件,python可以自己做软件吗
  7. 11月20日云栖精选夜读:围观阿里总部:边喝茶边搞技术是一种怎样的体验?
  8. cf----2019-08-14(The Doors,Zoning Restrictions Again,Detective Book)
  9. DApp 上线 BitPortal币通钱包申请指南
  10. 【Java基础】· Java基本语法:程序流程控制习题总结