<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>按钮特效</title>
<style type="text/css">
*
{
margin:0;padding:0
}
body
{
background:#666;
}
.box
{
width:800px;
height:280px;
margin:50px auto;
position:relative;
}
.box .link
{
width:205px;
height:280px;
float:left;
margin:0 20px;
}
.link .icon
{
display:inline-block;
width:100%;
height:190px;
transition:all 0.2s ease-out;
}
.link_miss .icon
{
background:url(yy.png) no-repeat center center;
}
.link_play .icon
{
background:url(yy.png) no-repeat center center;
}
.link_touch .icon
{
background:#F6C;
}
.link .icon:hover{transform:rotate(360deg) scale(1.2);/*这是css3的动画旋转特效*/
}
.button
{
padding-left:10px;
width:180px;
height:50px;
line-height:50px;
text-decoration:none;
color:#0C0;
font-family:"微软雅黑";
font-weight:bolder;
border:2px solid rgba(255,255,255,0.5);
display:block;
box-sizing:border-box;/*这是css3的新属性,这个意思是按照设定的欢度和高度执行 ,自动排除了边框*/
background:url(jj.png) no-repeat 130px center;
transition:all 0.4s ease;
position:relative;
}
.button:hover
{
border:2px solid rgba(255,255,255,1);
background-position:140px center;
}
.button .line
{
display:block;
position:absolute;
background:none;
transition:all 0.4s ease
}
.button:hover .line
{
background:#fff;
}
.button .line_top
{
left:-100%;
top:-2px;
width:0;
height:2px;
}
.button:hover .line_top
{
width:100%;
left:-2px;
}
.button .line_left
{
width:2px;
height:0;
left:-2px;
bottom:-120%;
}
.button:hover .line_left
{
height:100%;
bottom:-2px;
}
.button .line_bottom
{
width:0;
right:-100%;
height:2px;
bottom:-2px;
}
.button:hover .line_bottom
{
width:100%;
right:-2px;
}
.button .line_right
{
width:2px;
height:0;
right:-2px;
top:-110%;
}
.button:hover .line_right
{
height:100%;
top:-2px;
/*这是css3的动画过渡特性*/
}
.tip
{
position:absolute;
padding:0 14px;
height:35px;
line-height:35px;
background:#0F0;
color:#fff;
font-size:18px;
border-radius:3px;/*圆角属性*/
margin:0 auto;
top:100px;
opacity:0;/*css3属性设置元素的透明度*/
}
.tip em
{
font-style:normal;
}
.tip span
{
display:block;
width:0;
height:0;
border:7px solid transparent;
border-top-color:#0F0;
position:absolute;
top:35px;
left:50%;
margin-left:-3.5px;
}
</style>
<script src="http://libs.baidu.com/jquery/1.8.0/jquery.js" type="text/javascript"></script>
<script>
$(function(){
$(".link .button").hover(function(){
var title=$(this).attr("date");//先获取滑过的按钮的data属性值
var pos=$(this).position().left;//position()属性是获取元素和加了定位的父元素之间的距离 包括top和left
var dis=($(".tip").outerWidth()-$(this).outerWidth())/2;
var sj=pos-dis;
$(".tip em").text(title);//吧获取到的date的值 放在html结构的em中
$(".tip").css({"left":sj+"px"}).animate({"top":145,"opacity":1},500);
},
function(){
$(".tip").animate({"top":100,"opacity":0},500);
})
})
</script>
</head>
<body>
<div class="box">
<div class="link link_miss">
<span class="icon"></span>
<a href="#" class="button" date="这是mission aaaaaaaaa">mission
<span class="line line_top"></span>
<span class="line line_right"></span>
<span class="line line_bottom"></span>
<span class="line line_left"></span>
</a>
</div><!--第一个按钮结束-->
<div class="link link_play">
<span class="icon"></span>
<a href="#" class="button" date="这是play bbbbbbbbbbbb">play
<span class="line line_top"></span>
<span class="line line_right"></span>
<span class="line line_bottom"></span>
<span class="line line_left"></span>
</a>
</div><!--第二个按钮结束-->
<div class="link link_touch">
<span class="icon"></span>
<a href="#" class="button" date="这是touch ccccccccccccccc">touch
<span class="line line_top"></span>
<span class="line line_right"></span>
<span class="line line_bottom"></span>
<span class="line line_left"></span>
</a>
</div><!--第三个按钮结束-->
<div class="tip"><em></em><span></span></div>
</div>
</body>
</html>