暑假第14天,学习了幽灵按钮。
幽灵按钮,也就是Ghost Buttons,是一个透明的按钮,通常是矩形或者圆角矩形,仅保留基本的形制,使用细线来标识边界;按钮内的文字通常使用纤细的非衬线体字体的纯文本,来指明按钮功能。
幽灵按钮有时候也被称为“空按钮”,通常会被设计得比普通的按钮更大一些。而它们之所以被命名为“幽灵”,是应为这种按钮如同鬼魂一样透明,但是独特的造型会立刻吸引用户的注意力——正如同故事中鬼魂一样抓人眼球。
虽然你可能在大量的网站中看到幽灵按钮,但是并非所有的网站都和幽灵按钮相得益彰。真正适合幽灵按钮的是那些使用极简风和扁平风的网站和APP,使用大图背景的网站也与之非常搭。
效果是当点击上部图片图片会旋转和放大,用的transfrom:rotate,scale
当点击按钮,对应会在每个按钮上部出现提示框,并从四周向按钮内部出现动态线条
代码及解释如下:
代码如下:
html:
<!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" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
<link rel="stylesheet" type="text/css" href="./css/style.css">
<script src="js/jquery-1.8.3.min.js"></script>
<script src="js/script.js"></script>
</head>
<body>
<div class="box">
<div class="link link-mission">
<span class="icon"></span>
<a href="#" class="button" data="My mission is clear">
<span class="line line-top"></span>
<span class="line line-left"></span>
<span class="line line-right"></span>
<span class="line line-bottom"></span>
MISSION
</a>
</div>
<div class="link link-play">
<span class="icon"></span>
<a href="#" class="button" data="Come and Play ready">
<!-- 把四个线条设置内部元素,把提示信息放入data中随后用js取出并定位 -->
<span class="line line-top"></span>
<span class="line line-left"></span>
<span class="line line-right"></span>
<span class="line line-bottom"></span>
PLAY
</a>
</div>
<div class="link link-touch">
<span class="icon"></span>
<a href="#" class="button" data="This is my touch">
<span class="line line-top"></span>
<span class="line line-left"></span>
<span class="line line-right"></span>
<span class="line line-bottom"></span>
TOUCH
</a>
</div>
<!-- 提示文字信息 -->
<div class="tip"><em></em><span></span></div>
</div>
</body>
</html>
css:
*{
margin: 0px;
padding: 0px;
}
body{
background: #333;
}
.box{
width: 960px;
height: 280px;
margin:150px auto;
position: relative;
}
.box .link{
height:280px;
width: 200px;
float:left;
margin:0px 60px;
}
/*所有相同的属性都放在一个类里,每个不同的在设置一个类,减少代码量,还可以看的更清楚*/
.link .icon{
display: inline-block;
height: 190px;
width: 100%;
transition:all 0.5s ease-out;
-webkit-transition:all 0.5s ease-out;
-o-transition:all 0.5s ease-out;
-moz-transition:all 0.5s ease-out;
}
.link .icon:hover{
transform:rotate(360deg) scale(1.3);
-webkit-transform:rotate(360deg) scale(1.3);
-o-transform:rotate(360deg) scale(1.3);
-moz-transform:rotate(360deg) scale(1.3);
-ms-transform:rotate(360deg) scale(1.3);
}
.link-mission .icon{
background:url(../images/mission.png) no-repeat center center;
}
.link-play .icon{
background:url(../images/play.png) no-repeat center center;
}
.link-touch .icon{
background:url(../images/touch.png) no-repeat center center;
}
.button{
width:190px;
height: 50px;
text-decoration: none;
display: block;
position: relative;
line-height: 50px;
font-family: serif;
border:2px solid rgba(255,255,255,0.6);
color:#2DCB70;
font-size: 22px;
padding-left: 20px;
margin:0 auto;
/*box-sizing是使盒子大小等于设置的width和height,忽略padding等,这里就是190*/
box-sizing:border-box;
-ms-box-sizing:border-box;
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
-o-box-sizing:border-box;
/*这里注意background可以一次性设置图片url和位置,一个是左右,一个是上下*/
background: url(../images/allow.png) no-repeat 130px center;
transition:all 0.8s ease;
-webkit-transition:all 0.8s ease;
-o-transition:all 0.8s ease;
-moz-transition:all 0.8s ease;
-ms-transition:all 0.8s ease;
}
.button:hover{
background-position: 145px center;
border:2px solid rgba(255,255,255,1);
}
/*transition的ease是先快后慢再快,ease-out是先快后慢*/
.button .line{
display: block;
position:absolute;
background: none;
transition:all 2s ease;
-webkit-transition:all 0.4s ease;
-o-transition:all 0.4s ease;
-ms-transition:all 0.4s ease;
-moz-transition:all 0.4s ease;
}
.button:hover .line{
background: #fff;
}
.button .line-top{
left:-40%;
top:-2px;
width:0px;
height: 2px;
}
.button:hover .line-top{
left:-2px;
width:100%;
}
.button .line-left{
width:2px;
height: 0px;
bottom:-160%;
left:-2px;
}
.button:hover .line-left{
height:100%;
bottom:-2px;
}
.button .line-right{
width:2px;
height: 0px;
top:-160%;
right:-2px;
}
.button:hover .line-right{
height: 100%;
top:-2px;
}
/*1.每一条线都是这种方法设置,开始右一个点变成一条线
2.用transition使其变化
3.改变的其实就是位置,最后让他跟border重合
4.注意真正重合要设置bottom不是0;因为border本身还有宽度*/
.button .line-bottom{
right:-40%;
bottom:-2px;
width:0px;
height: 2px;
}
.button:hover .line-bottom{
right:-2px;
width:100%;
}
.tip{
position: absolute;
height:35px;
line-height: 35px;
padding: 0 14px;
background: #2DCB70;
color:#fff;
font-size: 18px;
margin:0 60px;
border-radius: 5px;
-webkit-border-radius: 5px;
-o-border-radius: 5px;
-moz-border-radius: 5px;
-ms-border-radius: 5px;
top:100px;
opacity: 0;
}
/*消除em原先的斜体*/
.tip em{
font-style: normal;
}
/*1.三角形的制作方法border-top-color设置顶的方向
2.注意要设置block
3.border的值的大小就是三角形的大小,注意设置成transparent
4.注意三角形位置设定要定位,相对去前面一个元素tip*/
.tip span{
display: block;
width:0px;
height: 0px;
border:7px solid transparent;
overflow: hidden;
border-top-color: #2DCB70;
position: absolute;
top:35px;
left:50%;
margin-left: -4px;
}
js:
//jquery显示上部提示框
$(document).ready(function(){
$(".link .button").hover(function() {
/* 划过时 */
//获取data中的值
var title = $(this).attr('data');
//document.title = title;调试的新方法,用document.title
//将对应值放入em中显示
$('.tip em').text(title);
var buttonPos = $(this).position().left-55;
//获取由于可适性多的那一步值,注意用outWidth获得真实的值,而width只能获取css中定义的值
var dis = ($('.tip').outerWidth() - $(this).outerWidth())/2;
var trueDis = buttonPos-dis;
//加入动画,并且让提示框出现在该出现的地方
$('.tip').css({'left':trueDis+'px'}).animate({'opacity': 1, 'top': 140}, 300);
}, function() {
/* 划出时 */
$('.tip').stop();
if(!$('.tip').is(':animated')){
$('.tip').animate({'top': 100,'opacity':0}, 300);
}
});
})