网页效果中常常会用到图片的hover效果,本文中展现的是使用Jquery书写的效果,相比较ImageHover.css兼容性更好。css
插件是使用jquery
书写的,因此兼容性比ImageHover.css更好。若是不须要考虑兼容性建议考虑 ImageHover.css 这个插件样式更多。html
Demo
:http://weber.pub/demo/160920/index.html 直接下载jquery
连接:http://pan.baidu.com/s/1qXPy5y8 密码:7b8iweb
一、css样式代码学习
.hover-down{ width: 285px; height: 150px; position: relative; overflow: hidden; } .hover-down img{ position: absolute; } .hover-down .hd-font{ position: absolute; width: 285px; height:150px; z-index: 1; margin-top: -150px; color: #ddd; background: #000; filter:alpha(opacity=80); -moz-opacity:0.8; opacity: 0.8; } .hd-font span{ padding: 20px; font-size: 14px; display: inline-block; line-height: 18px; } .hover-up{ width: 285px; height: 135px; position: relative; overflow: hidden; background: #fff; } .hover-up img{ width: 100px; } .hover-up .hu-font{ height: 135px; width: 285px; } .hover-up .qr{ position: absolute; width: 285px; height:135px; line-height: 135px; z-index: 1; margin-bottom: -135px; background: #fff; text-align: center; } .hover-up a{ color: #4b8ce5; } .hover-up a:hover{ color: #f8b600; }
二、HTML代码测试
<div class="hover-down"> <div class="hd-font"> <span>web.pub测试文字测试web.pub测试测试文字</span> </div> <img src="img/11.jpg" alt="web.pub测试文字测试"> </div> <div class="hover-up"> <div class="hu-font center pr-lg pl-lg"> <p class="f-20 c-333 mb-xs pt-md">web.pub</p> <p class="f-14 c-666 mb-none">web开发者-努力学习中、、</p> <hr class="solid mt-md mb-md"> <a href="" class="">参观网站</a> </div> <div class="qr"> <img src="img/qr.png" alt="web.pub"> </div> </div>
三、js代码 (须要引入jquery)网站
$('.hover-down').hover(function () { $(this).addClass(' case-test'); $('.case-test .hd-font').animate({marginTop:'0px'},'1000') },function () { $('.case-test .hd-font').animate({marginTop:'-150px'},'1000') $(this).removeClass(' case-test'); }) $('.hover-up').hover(function () { $(this).addClass(' case-test'); $('.case-test .qr').animate({marginTop:'-135px'},'1000') },function () { $('.case-test .qr').animate({marginTop:'0px'},'1000') $(this).removeClass(' case-test'); })
by Weber.pubthis