无需flash,完全用css就可以做出超炫的图片倒影效果。网上流传很多种版本,经过本人的一番研究,做成能够兼容firefox、chrome、IE等各主流浏览器的版本,跟大家分享一下。最终完成的效果
新浏览器的实现
指的是firefox、chrome和IE9。新浏览器都支持CSS3新添的transform属性,所以实现倒影效果非常简单。从下面的代码看到,各家浏览器对transform的实现有点不同
-webkit-transform: scaleY(-1); /* webkit内核浏览器的实现,例如safari */
-moz-transform: scaleY(-1); /* firefox 的实现 */
-ms-transform: scaleY(-1); /* IE 的实现 */
-o-transform: scaleY(-1); /* Opera的实现 */
HTML
复制代码代码如下:
<div class="wrap">
<div class="image"><img src="/UploadFiles/2021-03-30/1.jpg"><div class="down">
<div class="reflection"></div>
<div class="overlay"></div>
</div>
</div>
CSS
复制代码代码如下:
body{background:#000;color:#f00}
.wrap{position:relative;}
.image{margin-bottom:3px;}
.down{position: relative;}
.reflection{width:421px;height:180px;background:url(1.jpg) bottom center no-repeat;
-webkit-transform: scaleY(-1);
-moz-transform: scaleY(-1);
-ms-transform: scaleY(-1);
-o-transform: scaleY(-1);
transform: scaleY(-1);
opacity:0.5;
filter:alpha(opacity='50');
}
.overlay{position: relative;width:421px;height:180px;bottom:149px;
background-image: -moz-linear-gradient(center bottom, rgb(0,0,0) 20%, rgba(0,0,0,0) 90%);
background-image: -o-linear-gradient(rgba(0,0,0,0) 10%, rgb(0,0,0) 30%);
background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0.20, rgb(0,0,0)), color-stop(0.90, rgba(0,0,0,0)));
filter: progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColor=0, EndColorStr=#000000);
}
在倒转的图片上面还加了一个DIV.overlay层,做出渐变的效果,使倒影看起来更真实。
兼容旧浏览器的实现
考虑到还有相当多的人在使用旧版浏览器,程序员绞尽脑汁为这部分人做兼容。这里指的是IE7/IE8。IE6怎么办?提示用户升级浏览器吧。
旧IE不支持transform属性,可以使用滤镜 filter:flipv 来生成图片倒转,但会跟IE9的transform冲突。所以要用到各种 hack 来解决。修改后的CSS如下,添加了IE9 hack,覆盖掉上面的filter:flipv的属性。
复制代码代码如下:
body{background:#000;color:#f00}
.wrap{position:relative;}
.image{margin-bottom:3px;}
.down{position: relative;}
.reflection{width:421px;height:180px;background:url(1.jpg) bottom center no-repeat;
-webkit-transform: scaleY(-1);
-moz-transform: scaleY(-1);
-ms-transform: scaleY(-1);
-o-transform: scaleY(-1);
transform: scaleY(-1);
opacity:0.5;
filter:flipv alpha(opacity='50'); /*ALL IE*/
}
@media all and (min-width:0) {
.reflection{filter:alpha(opacity='50') \0/;} /*IE9*/
}
.overlay{position: relative;width:421px;height:180px;bottom:149px;
background-image: -moz-linear-gradient(center bottom, rgb(0,0,0) 20%, rgba(0,0,0,0) 90%);
background-image: -o-linear-gradient(rgba(0,0,0,0) 10%, rgb(0,0,0) 30%);
background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0.20, rgb(0,0,0)), color-stop(0.90, rgba(0,0,0,0)));
filter: progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColor=0, EndColorStr=#000000);
}
运行一下,在各版本的浏览器能看到最终的效果了。
新浏览器的实现
指的是firefox、chrome和IE9。新浏览器都支持CSS3新添的transform属性,所以实现倒影效果非常简单。从下面的代码看到,各家浏览器对transform的实现有点不同
-webkit-transform: scaleY(-1); /* webkit内核浏览器的实现,例如safari */
-moz-transform: scaleY(-1); /* firefox 的实现 */
-ms-transform: scaleY(-1); /* IE 的实现 */
-o-transform: scaleY(-1); /* Opera的实现 */
HTML
复制代码代码如下:
<div class="wrap">
<div class="image"><img src="/UploadFiles/2021-03-30/1.jpg"><div class="down">
<div class="reflection"></div>
<div class="overlay"></div>
</div>
</div>
CSS
复制代码代码如下:
body{background:#000;color:#f00}
.wrap{position:relative;}
.image{margin-bottom:3px;}
.down{position: relative;}
.reflection{width:421px;height:180px;background:url(1.jpg) bottom center no-repeat;
-webkit-transform: scaleY(-1);
-moz-transform: scaleY(-1);
-ms-transform: scaleY(-1);
-o-transform: scaleY(-1);
transform: scaleY(-1);
opacity:0.5;
filter:alpha(opacity='50');
}
.overlay{position: relative;width:421px;height:180px;bottom:149px;
background-image: -moz-linear-gradient(center bottom, rgb(0,0,0) 20%, rgba(0,0,0,0) 90%);
background-image: -o-linear-gradient(rgba(0,0,0,0) 10%, rgb(0,0,0) 30%);
background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0.20, rgb(0,0,0)), color-stop(0.90, rgba(0,0,0,0)));
filter: progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColor=0, EndColorStr=#000000);
}
在倒转的图片上面还加了一个DIV.overlay层,做出渐变的效果,使倒影看起来更真实。
兼容旧浏览器的实现
考虑到还有相当多的人在使用旧版浏览器,程序员绞尽脑汁为这部分人做兼容。这里指的是IE7/IE8。IE6怎么办?提示用户升级浏览器吧。
旧IE不支持transform属性,可以使用滤镜 filter:flipv 来生成图片倒转,但会跟IE9的transform冲突。所以要用到各种 hack 来解决。修改后的CSS如下,添加了IE9 hack,覆盖掉上面的filter:flipv的属性。
复制代码代码如下:
body{background:#000;color:#f00}
.wrap{position:relative;}
.image{margin-bottom:3px;}
.down{position: relative;}
.reflection{width:421px;height:180px;background:url(1.jpg) bottom center no-repeat;
-webkit-transform: scaleY(-1);
-moz-transform: scaleY(-1);
-ms-transform: scaleY(-1);
-o-transform: scaleY(-1);
transform: scaleY(-1);
opacity:0.5;
filter:flipv alpha(opacity='50'); /*ALL IE*/
}
@media all and (min-width:0) {
.reflection{filter:alpha(opacity='50') \0/;} /*IE9*/
}
.overlay{position: relative;width:421px;height:180px;bottom:149px;
background-image: -moz-linear-gradient(center bottom, rgb(0,0,0) 20%, rgba(0,0,0,0) 90%);
background-image: -o-linear-gradient(rgba(0,0,0,0) 10%, rgb(0,0,0) 30%);
background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0.20, rgb(0,0,0)), color-stop(0.90, rgba(0,0,0,0)));
filter: progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColor=0, EndColorStr=#000000);
}
运行一下,在各版本的浏览器能看到最终的效果了。
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
暂无评论...
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。
更新日志
2024年09月22日
2024年09月22日
- 【发烧唱片】Naim《示范碟(第二辑)》1999[WAV+CUE]
- 《优米雅的炼金工房》“妮娜”战斗实机:大雷黑丝金发御姐
- 许冠杰.2003-四合一珍藏集4CD【宝丽金】【WAV+CUE】
- 李宇春.2014-1987我不知会遇见你【天娱传媒】【WAV+CUE】
- 梁汉文.1995-抱着你感觉很好【华星】【WAV+CUE】
- 《情歌回首 HIFI国语老歌 2CD》[WAV/分轨][1.2GB]
- 《降央卓玛 草原绝色醇美的歌声 金色的卓玛》[WAV/分轨][520MB]
- 《赵雷 30首经典城市民谣 2CD》[WAV/分轨][1.3GB]
- 仙境传说新启航兑换码怎么使用 仙境传说兑换码使用方法
- 魔兽世界地心之战武器战用什么饰品 地心之战武器战饰品推荐
- 仙境传说新启航一区是哪个区 仙境传说一区服务器介绍
- 叶倩文2014《影视金曲》LPCD45【WAV+CUE】
- 张国荣1996-哥哥的前半生[华星]2CD[WAV]
- 银霞.1981-《泥泞中的小花·期待》台湾复刻版[WAV+CUE]
- PS掌机游玩《宇宙机器人》体验测试 玩家:这游戏就得用便携模式玩!