GVKun编程网logo

使用CSS+JavaScript或纯js实现半透明遮罩效果的实例分享(css半透明遮罩层)

11

对于想了解使用CSS+JavaScript或纯js实现半透明遮罩效果的实例分享的读者,本文将提供新的信息,我们将详细介绍css半透明遮罩层,并且为您提供关于CoffeeScript或纯JavaScri

对于想了解使用CSS+JavaScript或纯js实现半透明遮罩效果的实例分享的读者,本文将提供新的信息,我们将详细介绍css半透明遮罩层,并且为您提供关于CoffeeScript或纯JavaScript?、CSS+Js遮罩效果的TAB及焦点图片切换(推荐)_javascript技巧、CSS3的新特性一览:如何使用CSS3实现半透明效果、javascript ImgBox透明遮罩层背景图片展示_javascript技巧的有价值信息。

本文目录一览:

使用CSS+JavaScript或纯js实现半透明遮罩效果的实例分享(css半透明遮罩层)

使用CSS+JavaScript或纯js实现半透明遮罩效果的实例分享(css半透明遮罩层)

CSS+JavaScript

实现原理: 创建一个满屏的div,使用绝对定位,这样的话它就可以脱离文档流,对其他的元素不会产生影响,并且将其设置为半透明状态,当然这个透明度可以随便调的,同时创建一个login元素,它也使用绝对定位,并将其z-index属性值大于面屏的div,这个时候它就不会被满屏div遮盖。在默认状态下这两个div的display属性值是none。当点击相应的按钮可以更改他们的display属性值。

rush:js;">

<Meta charset=" utf-8">

CSS如何实现弹出<a href="https://www.jb51.cc/tag/yige/" target="_blank">一个</a>全屏灰黑色透明遮罩<a href="https://www.jb51.cc/tag/xiaoguo/" target="_blank">效果</a>-小编

<style type="text/css">

{

margin:0px;

padding:0px;

}

.zhezhao

{

width:100%;

height:100%;

background-color:#000;

filter:alpha(opacity=50);

-moz-opacity:0.5;

opacity:0.5;

position:absolute;

left:0px;

top:0px;

display:none;

z-index:1000;

}

.login

{

width:280px;

height:180px;

position:absolute;

top:200px;

left:50%;

background-color:#000;

margin-left:-140px;

display:none;

z-index:1500;

}

.content

{

margin-top:50px;

color:red;

line-height:200px;

height:200px;

text-align:center;

}

<script type="text/javascript">

window.onload=function()

{

var zhezhao=document.getElementById("zhezhao");

var login=document.getElementById("login");

var bt=document.getElementById("bt");

var btclose=document.getElementById("btclose");

bt.onclick=function()

{

zhezhao.style.display="block";

login.style.display="block";

}

btclose.onclick=function()

{

zhezhao.style.display="none";

login.style.display="none";

}

}

<divid="zhezhao">

<divid="login"><button id="btclose">点击关闭

CoffeeScript或纯JavaScript?

CoffeeScript或纯JavaScript?

当平均ASP.net C#程序员(具有非常差的 JavaScript知识,除了脚本编写一些hide()show()效果)将不得不从构建ASP.net WebForms应用程序切换到RIA JavaScript应用程序(客户端 – 服务器架构).

对他来说可能不那么痛苦:

>学习CoffeeScript并将其用于“编码JavaScript”?
>正确学习JavaScript并直接使用?

我在想

>正确调试
>编码语法
> …

有没有人在类似的情况下有经验?

解决方法

过去几天,我们在 Stackoverflow Javascript Chat年对这个话题进行了很长时间的讨论.一般的结论是,CoffeeScript是一个很好的工具,可能会创建“好”的JavaScript代码.然而,如果你知道你在做什么,你可能想直接在javascript中编码,而不需要半编译的“高级”语言.

我没有真正的CoffeeScript经验,所以如果我说错了,我很乐意得到纠正.例如,我不知道CoffeeScript如何反应ECMAscript3到5(甚至6)差异. CoffeeScript会自动为每个代码创建回退代码,还是仅生成ES3代码?

所有这些问题和疑虑是我尽可能使用简单的Javascript的一个原因.如果你不太在意,发生什么事情,你需要快速的结果,这可能是一个很好的方法.

CSS+Js遮罩效果的TAB及焦点图片切换(推荐)_javascript技巧

CSS+Js遮罩效果的TAB及焦点图片切换(推荐)_javascript技巧

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
<title>Js遮罩效果的TAB及图片切换</title> 
<style> 
div, ul, ol, li, dl, dt, dd { 
margin:0; 
padding:0; 
} 
.imgFlash,.tab{margin:auto} 
/*------焦点图片的css-------*/ 
.imgFlash { 
height:230px;width:270px; 
position:relative; 
} 
.imgFlash dl { 
    height:100%; 
    overflow:hidden; 
    position:absolute; 
    width:100%; 
} 
.imgFlash img { 
    height:100%; 
    position:absolute; 
    width:100%; 
    background-color: #FFFFFF; 
    background-repeat: no-repeat; 
    background-position: center center; 
} 
.imgFlash dt { 
bottom:0; 
font-size:12px; 
height:24px;line-height:24px; 
left:0; 
position:absolute; 
width:100%; 
z-index:1; 
} 
.imgFlash dt span { 
    background-color:#000000; 
    height:100%; 
    opacity:0.4;filter:Alpha(Opacity=40); 
    position:absolute; 
    width:100%; 
} 
.imgFlash dt a { 
color:#FFFFFF; 
position:absolute; 
text-decoration:none; 
text-indent:5px; 
z-index:1; 
} 
.imgFlash dt a:hover { 
text-decoration:underline; 
} 
.imgFlash div { 
bottom:8px; 
cursor:pointer; 
display:block; 
position:absolute; 
right:8px; 
z-index:99999; 
} 
.imgFlash div em { 
background-color:#000000; 
border:1px solid #FFFFFF; 
display:block; 
float:right; 
height:4px; 
margin-right:3px; 
filter:Alpha(Opacity=50);opacity:0.5; 
overflow:hidden; 
width:4px; 
} 
.imgFlash div em.d {/*激活的小方块的样式*/ 
background-color:#CC0000; 
filter:Alpha(Opacity=80); 
opacity:0.8; 
} 
/*-------------------------Tab的css----------------------------*/ 
.tab,.tab ul{list-style-type: none;} 
.tab{ 
    width:270px; 
    background-color:#FFFFFF; 
    height: 160px; 
    font-size: 12px; 
    position: relative; 
    border-top-width: 30px; 
    border-right-width: 1px; 
    border-bottom-width: 1px; 
    border-left-width: 1px; 
    border-top-style: solid; 
    border-right-style: solid; 
    border-bottom-style: solid; 
    border-left-style: solid; 
    border-top-color: #0066FF; 
    border-right-color: #0066FF; 
    border-bottom-color: #0066FF; 
    border-left-color: #0066FF; 
} 
.tab ul { 
    position: absolute; 
    top: -30px; 
} 
.tab li{ 
    float:left; 
    background-color:#A9CEEB; 
    background-repeat:no-repeat; 
    background-position:left top; 
    margin-top:5px; 
    margin-left: 5px; 
} 
.tab li.d { 
    background-color: #FFFFFF; 
} 
.tab li a{text-decoration:none;display:block;padding-right:8px;padding-left:8px;line-height:25px;color:#2B6FA2;} 
.tab li.d a{color:#0C3E74;} 
.tab li ul{ 
    border-bottom-style:none; 
    position:absolute; 
    left:0px; 
    top:30px; 
    background-color: #FFFFFF; 
    padding-top: 10px; 
    width: 270px; 
} 
.tab li li{ 
    float:none; 
    background-image:none; 
    margin:0px; 
    background-color: #FFFFFF; 
} 
.tab li li a{ 
    background-image:none; 
    line-height:22px; 
    color: #000000; 
    float: none; 
    height: 22px; 
} 
.tab li ul li a:hover{text-decoration:underline;} 
.tab li.d li a{color:#000000;} 
</style> 
<script language="javascript"> 
var $ = function (d){return document.getElementById( d );}; 
var isIE = (document.all) ? true : false; 
var Bind = function (obj,fun,arr){return function() {arr || (arr = arguments);return fun.apply(obj,arr);}};//绑定 
var Tween = function(t,b,c,d){return c*t/d + b;};//缓冲函数 
function addEventHandler(oTarget, sEventType, fnHandler) {if (oTarget.addEventListener) {oTarget.addEventListener(sEventType, fnHandler, false);} else if (oTarget.attachEvent) {oTarget.attachEvent("on" + sEventType, fnHandler);} else {oTarget["on" + sEventType] = fnHandler; 
    } 
};//事件监听 
function removeEventHandler(oTarget, sEventType, fnHandler) { 
if (oTarget.removeEventListener) { 
oTarget.removeEventListener(sEventType, fnHandler, false); 
} else if (oTarget.detachEvent) { 
oTarget.detachEvent("on" + sEventType, fnHandler); 
} else { 
oTarget["on" + sEventType] = null; 
} 
};//移除监听 

var Timer = {};//Timer 
Timer.add = function (fn){return new this.fn(fn)}; 
Timer.fn = function (fn){ 
var timer; 
this.play = function (speed,only){ 
speed || ( speed = 10 ); 
    if(only)timer = window.setTimeout(fn,speed); 
else timer = window.setInterval(fn,speed); 
}; 
this.stop = function (){clearTimeout(timer);clearInterval(timer)}; 
}; 
//Mask 遮罩动画 
var Mask = function (){ 
     this.fl = Timer.add(Bind(this,this.fn)); 
     this.from_num = 0; 
     this.speed = 50;//动画速度,越大越慢 
}; 
Mask.prototype.ready = function (ele,pos){ 
if(this.ele)this.set(this.maxWidth,this.maxHeight); 
this.ele = ele; 
this.maxWidth = this.ele.offsetWidth; 
     this.maxHeight = this.ele.offsetHeight; 
     this.ele.style.position = "absolute"; 
     this.from_num = 0; 
     if(!pos){ 
         var x = ["left","center","right",""][parseInt(4*Math.random())], 
y = ["top","center","bottom",""][parseInt(4*Math.random())]; 
        if(x == "" && y == "")x = "left";//避免同时为""     
     this.position = [x,y];         
     }else{ 
     this.position = pos; 
     } 
     this.set(0,0); 
     this.fl.stop(); 
}; 
Mask.prototype.start = function (){this.fl.play();}; 
Mask.prototype.stop = function (){this.fl.stop();}; 
Mask.prototype.set = function (width,height){//设置遮罩的矩形,用于定位遮罩的变换方向 
var t,r,b,l; 
    switch(this.position[0]){ 
     case "left" : 
     l = 0; 
         r = width; 
         break; 
     case "center" : 
     l = (this.maxWidth - width)/2; 
         r = (this.maxWidth + width)/2; 
         break; 
     case "right" : 
     l = this.maxWidth - width; 
         r = this.maxWidth; 
         break; 
     default: 
     l = 0; 
         r = this.maxWidth;      
    } 
switch(this.position[1]){ 
     case "top" : 
     t = 0; 
         b = height; 
         break; 
     case "center" : 
     t = (this.maxHeight - height)/2; 
         b = (this.maxHeight + height)/2; 
         break; 
     case "bottom" : 
     t = this.maxHeight - height; 
         b = this.maxHeight; 
         break; 
     default : 
     t = 0; 
         b = this.maxHeight; 
         break;     
    } 
    this.ele.style.clip = "rect(" 
    + t + "px," 
    + r + "px," 
    + b + "px," 
    + l + "px)" ; 
}; 
Mask.prototype.fn = function (){ 
var w,h; 
this.from_num ++ ; 
     if(this.from_num<=this.speed){ 
     w = Tween(this.from_num,0,this.maxWidth,this.speed); 
        h = Tween(this.from_num,0,this.maxHeight,this.speed); 
        this.set(w,h); 
     }else{ 
     this.fl.stop(); 
        //this.start();//若不需要重复动画,把这句注释,上句不注释 
     } 
     
}; 
function ImgFlash(box){ 
this.box = box.getElementsByTagName("dl"); 
        this.ge = 4;//切换间隔秒数 
        this.menu = []; 
        this.mask = new Mask();//加载遮罩动画,不设置参数 即 随机效果 
        this.zIndex = this.box.length; 
        var _div = document.createElement(&#39;div&#39;); 
        this.dang = 0; 
        for(i=0;i<this.zIndex;i++){ 
            this.box[i].style.zIndex = this.zIndex-i; 
            var _em = document.createElement(&#39;em&#39;),_span = document.createElement(&#39;span&#39;); 
            var _dt = this.box[i].getElementsByTagName("dt")[0]; 
            _dt.appendChild(_span); 
            addEventHandler(_em,&#39;mouseover&#39;,Bind(this,this.emEvent,[this.zIndex-i-1,true])); 
            _div.appendChild(_em); 
            this.menu.push(_em); 
            if(this.zIndex-i==1){ 
            _em.className = &#39;d&#39;; 
            } 
        } 
        box.appendChild(_div); 
        addEventHandler(box,&#39;mouseover&#39;,Bind(this,function(){this.fl.stop()})); 
        addEventHandler(box,&#39;mouseout&#39;,Bind(this,function(){this.fl.play(this.ge*1000)})); 
        this.fl = Timer.add(Bind(this,this.enterFrame)) 
        this.fl.play(this.ge*1000); 
} 
ImgFlash.prototype.enterFrame = function(){ 
var ddd = this.dang==2?0:this.dang+1; 
        this.emEvent(ddd);     
}; 
ImgFlash.prototype.emEvent = function (index,b){ 
        if(b)this.fl.stop(); 
        if(index == this.dang)return; 
        this.menu[this.menu.length-1-this.dang].className=""; 
        var odl = this.box[this.dang]; 
        this.zIndex++; 
        this.dang = index; 
        this.menu[this.menu.length-1-this.dang].className="d"; 
        var ndl = this.box[this.dang]; 
        var img = ndl.getElementsByTagName("img")[0]; 
        this.mask.ready(img); 
        this.mask.start(); 
        ndl.style.zIndex = this.zIndex; 
} 
function Tab(id,type){ 
var nav = id.getElementsByTagName("ul")[0].childNodes; 
var _nav,i=0; 
this.mask = new Mask();//初始化遮罩动画 
this.z = 1000; 
while(_nav = nav[i++]){ 
if(_nav.className=="d")this.focusEle = _nav; 
if(_nav.childNodes.length>1){ 
var A = _nav.getElementsByTagName("A")[0]; 
addEventHandler(A,type,Bind(this,fun,[A])); 
} 
if(_nav.nodeType == 1)_nav.getElementsByTagName("UL")[0].style.zIndex = nav.length-i; 
} 
function fun(ele){ 
var li = ele.parentNode; 
var ul = li.getElementsByTagName("UL")[0]; 
this.z += 1 
ul.style.zIndex = this.z; 
if(li.className=="d")return; 
li.className+=(li.className.length>0? " ": "") + "d"; 
this.focusEle.className=this.focusEle.className.replace(/( ?|^)d\b/g, ""); 
this.focusEle = li; 
this.mask.ready(ul); 
this.mask.start(); 
}; 
} 
</script> 
</head> 
<body> 
<divid="box"> 
     <dl> 
     <dt><a href="#">神秘花园</a></dt> 
    <dd><a href="#"><img  src="http://files.jb51.net/demoimg/200911/wall_s1.jpg" border="0" / alt="CSS+Js遮罩效果的TAB及焦点图片切换(推荐)_javascript技巧" ></a></dd> 
     </dl> 
     <dl> 
     <dt><a href="#">演示</a></dt> 
    <dd><a href="#"><img  src="http://files.jb51.net/demoimg/200911/wall_s2.jpg" border="0" / alt="CSS+Js遮罩效果的TAB及焦点图片切换(推荐)_javascript技巧" ></a></dd> 
     </dl> 
     <dl> 
     <dt><a href="#">人间仙境</a></dt> 
    <dd><a href="#"><img  src="http://files.jb51.net/demoimg/200911/wall_s3.jpg" border="0" / alt="CSS+Js遮罩效果的TAB及焦点图片切换(推荐)_javascript技巧" ></a></dd> 
     </dl> 
</div> 

 

 

 

 
<divid="tab1"> 
<ul> 
<li><a href="javascript:;">WEB前端</a> 
<ul> 
<li><a href="/soft/6675.shtml" target="_blank">VB封装一个文本文件读写类含示例</a></li><li><a href="/soft/6680.shtml" target="_blank">Csdn网站右下角的滑出弹出提示(带关闭功能)</a></li><li><a href="/soft/6668.shtml" target="_blank">VC++做的精美仿XP开始菜单</a></li><li><a href="/soft/6660.shtml" target="_blank">VB+Access学生综合档案管理系统</a></li><li><a href="/soft/6669.shtml" target="_blank">Delphi随机抽取幸运观众Access数据库版</a></li><li><a href="/soft/6665.shtml" target="_blank">多线程的VC++高速文件搜索代码</a></li> 
</ul> 
</li> 
<li><a href="javascript:;">源码下载</a> 
    <ul> 
     <li><a href="/soft/6638.shtml" target="_blank">15个jQuery学习实例(菜单、滚动、层隐藏等)</a></li><li><a href="/soft/6647.shtml" target="_blank">VB取汉字拼音首码(第一个字母)源码</a></li><li><a href="/soft/6646.shtml" target="_blank">VB 多进制转换源程序</a></li><li><a href="/soft/6657.shtml" target="_blank">杰奇网站管理系统 JIEQI CMS v1.7</a></li> 
</ul> 
</li> 
<li><a href="javascript:;">短标题</a> 
    <ul> 
    <li><a href="/soft/2182.shtml" target="_blank">Delphi版视频监控系统</a></li><li><a href="/soft/1852.shtml" target="_blank">《Java2核心技术卷2:高级特性》第7版中文高清 PDF</a></li><li><a href="/soft/2674.shtml" target="_blank">基于Delphi的HIS自动更新程序 v2.0</a></li><li><a href="/soft/2972.shtml" target="_blank">C#早期开发的摄像头监控系统源码</a></li><li><a href="/soft/3715.shtml" target="_blank">随机密码生成器VC++源程序</a></li> 
</ul> 
</li> 
<li><a href="javascript:;">更短</a> 
<ul> 
<li><a href="/soft/4561.shtml" target="_blank">C# 酒店管理(SQL2005)</a></li><li><a href="/soft/3041.shtml" target="_blank">云台C#家庭视频监控系统完整版</a></li><li><a href="/soft/3228.shtml" target="_blank">VS2008开发的C#高校宿舍管理系统</a></li><li><a href="/soft/3330.shtml" target="_blank">C#落雪无痕IP端口扫描器VS2005</a></li><li><a href="/soft/4339.shtml" target="_blank">火狐浏览器 Firefox v3.5</a></li> 
</ul> 
</li> 
</ul> 
</div> 
<script> 
new ImgFlash($("box"));//初始化 
new Tab($("tab1"),"mouseover"); 
</script> 
</body> 
</html>
登录后复制

其实这个不只是效果,代码也是非常值得学习的。大家主要是注意页面最下面的代码
<script> <br/>new ImgFlash($("box"));//初始化 <br/>new Tab($("tab1"),"mouseover"); <br/></script>  

CSS3的新特性一览:如何使用CSS3实现半透明效果

CSS3的新特性一览:如何使用CSS3实现半透明效果

css3的新特性一览:如何使用css3实现半透明效果

CSS3的新特性一览:如何使用CSS3实现半透明效果

CSS3作为前端开发者必备的技能之一,带来了更多强大、灵活的样式效果。其中,半透明效果是CSS3的一个重要特性,通过使用透明度属性可以实现页面元素的部分透明效果。本文将介绍如何使用CSS3中的透明度属性来实现半透明效果,并提供一些代码示例供参考。

一、使用透明度属性

在CSS3中,使用透明度属性可以实现元素的半透明效果。通过设置元素的透明度值,可以控制元素的不透明程度。透明度的值范围是从0到1,其中0表示完全透明,1表示完全不透明。

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

下面是一个简单的示例,展示如何使用透明度属性实现半透明效果。

<!DOCTYPE html>
<html>
<head>
<style>
div {
  background-color: rgba(255, 0, 0, 0.5);
  width: 300px;
  height: 200px;
}
</style>
</head>
<body>

<h1>半透明效果示例</h1>

<div>
  <h2>这是一个半透明的元素</h2>
  <p>这是一个示例文本,展示如何使用透明度属性来实现半透明效果。</p>
</div>

</body>
</html>
登录后复制

在上面的示例中,div元素的背景颜色使用rgba(Red,Green,Blue,Alpha)属性定义。其中,rgba属性的四个参数分别表示红、绿、蓝三个颜色通道的值,以及透明度的值。在上面的示例中,我们设置了红色,绿色,蓝色通道的值分别为255,0,0,透明度的值为0.5。这样设置后,div元素的背景颜色会显示出50%的不透明度,实现了半透明的效果。

二、使用透明度属性实现不同效果

除了常规的半透明效果,透明度属性还可以用于创建一些有趣的效果。下面是一些示例,展示了如何使用透明度属性实现不同的效果。

1.透明按钮

<!DOCTYPE html>
<html>
<head>
<style>
button {
  background-color: rgba(0, 0, 255, 0.5);
  width: 100px;
  height: 30px;
  border: none;
  color: white;
}
</style>
</head>
<body>

<h1>透明按钮示例</h1>

<button>点击我</button>

</body>
</html>
登录后复制

在上面的示例中,我们使用了透明度属性来实现一个透明按钮。按钮元素的背景颜色设置了50%的透明度,使得按钮背景呈现出半透明的效果。

2.透明背景

<!DOCTYPE html>
<html>
<head>
<style>
div {
  background-color: rgba(0, 0, 0, 0.5);
  width: 300px;
  height: 200px;
}
p {
  color: white;
  font-size: 20px;
}
</style>
</head>
<body>

<h1>透明背景示例</h1>

<div>
  <p>这是一个透明背景的元素</p>
</div>

</body>
</html>
登录后复制

在上面的示例中,我们使用透明度属性实现了一个透明背景的效果。div元素的背景颜色设置了50%的透明度,使得div元素的背景呈现出半透明的效果。同时,我们将p元素的文字颜色设置为白色,以便与背景产生对比。

通过上述示例可以看出,使用透明度属性可以轻松实现页面元素的半透明效果。这为页面设计师提供了更多的样式选择和设计空间。通过合理运用透明度属性,可以创造出更加醒目、吸引人的页面效果。

总结

本文介绍了CSS3中透明度属性的使用方法,并提供了一些代码示例。通过合理运用透明度属性,我们可以实现页面元素的半透明效果,以及一些有趣的效果。希望本文对您了解CSS3的透明度属性有所帮助,也希望您能在实际开发中灵活运用该特性,创造出更加出色的前端作品。

以上就是CSS3的新特性一览:如何使用CSS3实现半透明效果的详细内容,更多请关注php中文网其它相关文章!

javascript ImgBox透明遮罩层背景图片展示_javascript技巧

javascript ImgBox透明遮罩层背景图片展示_javascript技巧


[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]

注意上面的图片地址,大家自己

今天关于使用CSS+JavaScript或纯js实现半透明遮罩效果的实例分享css半透明遮罩层的讲解已经结束,谢谢您的阅读,如果想了解更多关于CoffeeScript或纯JavaScript?、CSS+Js遮罩效果的TAB及焦点图片切换(推荐)_javascript技巧、CSS3的新特性一览:如何使用CSS3实现半透明效果、javascript ImgBox透明遮罩层背景图片展示_javascript技巧的相关知识,请在本站搜索。

本文标签:

上一篇js实现的简单图片浮动效果完整实例(js实现图片滑动)

下一篇如何让一个json文件显示在表格里【实现代码】(将json数据显示在表格里)