html中图片亮度调节,HTML+CSS+JS 模仿 Win10 亮度调节效果
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 亮度调节效果相关推荐
- html中亮度怎么写,HTML+CSS+JS模仿win10亮度调节效果的示例代码
HTML+CSS+JS模仿win10亮度调节效果 代码 模仿win10的亮度调节 .control_bar{ height:200px; width:500px; border-bottom:3px ...
- html的window效果,HTML+CSS+JS模仿win10亮度调节效果
HTML+CSS+JS模仿win10亮度调节效果 代码 模仿win10的亮度调节 .control_bar{ height:200px; width:500px; border-bottom:3px ...
- HTML模仿win10亮度调节效果
HTML+CSS+JS模仿win10亮度调节效果 代码 <!doctype html> <html><head><meta charset="utf ...
- JAVA中解决Filter过滤掉css,js,图片文件等问题
JAVA中解决Filter过滤掉css,js,图片文件等问题 参考文章: (1)JAVA中解决Filter过滤掉css,js,图片文件等问题 (2)https://www.cnblogs.com/er ...
- html+css+js实现自动敲文字效果
html+css+js实现自动敲文字效果 简介:本文是一个前端案例的讲解,关于如何用html+css+js制作出逐渐显示出文字的效果,这个效果可以帮助大家在新人面前装一波. 效果展示 效果就是这个样子 ...
- css中图片整合的使用,CSS Sprites:图片整合技术详细案例
CSS Sprites 的目的就是通过整合图片,减少对服务器的请求数量,从而加快页面加载速度.介绍了CSS Sprites技术的实现方法,优点和缺点.最后通过实例CSS Sprites技术制作导航栏演 ...
- css让图片显示圆角 纯CSS绘制漂亮的圆形图案效果
css让图片显示圆角 样式: border-radius:5px 15px 20px 25px;顺序依次是上右下左 纯CSS绘制漂亮的圆形图案效果 .circle { border-radius: 5 ...
- eclipse中添加aptana插件(html.css.js自动提示)
一.关于aptana aptana是一款很不错的插件,本人主要用于安装此类插件,在eclipse中用于编辑javascript代码,html代码,和css代码的,因为其有自动纠错功能,当然安装后的问题 ...
- 怎样在html中插入广告,用div+css+js在文章中间插入广告
js如下,根据实际情况进行细节调整/// 正文画中画广告 var curUrl = window.location.href; var AdTxt=' try{ var contAd = docume ...
最新文章
- 前置体验,才是打动用户的神器
- 基于JWT的Token认证机制实现
- 操作系统 实验3【动态分区存储管理】
- 润乾报表列太多导致渲染速度慢_报表自动化: 如何选择可视化大屏开发利器
- java 生成缩略图类_JAVA生成【缩略图】方法
- 腾讯砸1亿斗地主欢乐豆签约前《英雄联盟》电竞职业选手Uzi
- 微信内测新功能:公众号们脖子一凉...
- mysql源码启动_mysql源码分析-启动过程
- php是什么电器元件,第三代计算机采用的主要电子元器件是什么
- Android开发-数据回传
- java ee 酒店管理系统,基于jsp的小型酒店管理系统-JavaEE实现小型酒店管理系统 - java项目源码...
- 用Axure做页面原型设计
- 蚁群算法原理及python实现
- 谷歌内核浏览器无法下载文件的解决方法
- 系统性能统计(CPU占用率,内存占用率,系统平均负载)
- 【乱七八糟的笔记】——前缀树
- 【Bioinfo Blog 011】【R Code 008】——功能富集分析
- 单调有界定理适用于函数吗_用极限定义证明一些极限的性质定理
- iPhone X(iOS 14.6)在Win 10上使用iRemoval PRO v5.1.2进行越狱
- java有趣的技术分享ppt,java面试数据结构与算法高频考
热门文章
- Spring 让 LOB 数据操作变得简单易行
- 苹果历代产品中的8大亮点设计(上)
- 用户获取pppd拨号状态_iPhone手机隐藏的拨号键代码,原来还能这么用,幸好钱没白花...
- 从零双排java之转换流
- 太原市山大附中2021年高考成绩查询,2021年太原高考状元名单公布,太原高考状元学校资料及最高分...
- 怎样利用python做一个软件,python可以自己做软件吗
- 11月20日云栖精选夜读:围观阿里总部:边喝茶边搞技术是一种怎样的体验?
- cf----2019-08-14(The Doors,Zoning Restrictions Again,Detective Book)
- DApp 上线 BitPortal币通钱包申请指南
- 【Java基础】· Java基本语法:程序流程控制习题总结