1.解析纯ccs判定鼠标方向,其实就在我可以先画8个长方形,方便验证ccs进入方向
image.png
2.然后每个长方形里面包含四个长方形,效果如下
image.png
这里说下四个长方形是跟父长方形大小一致的, 但是通过rotate(45deg)得到的,然后想不同方向位移,
这样子,可以监听到父类上线左右鼠标的进入,但是会多出的部分,我们需要在父类div加入
overflow:hidden
这个属性,这样就可以完美监听到鼠标进入的方向了。
完整代码:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>蚂蚁部落</title>
<style type="text/css">
.antzone {
width: 1000px;
height: auto;
overflow: hidden;
cursor: pointer;
}
.antzone [fox=con] {
width: calc((990px - 10px * 3) / 4);
background: url(demo/CSS/img/shangpin.jpg) -616px 0 no-repeat;
height: calc((990px - 10px * 3) / 4 / 3 * 4);
position: relative;
overflow: hidden;
margin: 10px 10px 0 0;
float: left;
}
.antzone [fox=con] [fox$=_c]:nth-of-type(2n-1) {
width: 240px;
height: 240px;
transform: rotate(45deg) skew(8deg,8deg);
position: absolute;
left: 2px;
}
.antzone [fox=con] [fox$=_c]:nth-of-type(2n) {
width: 240px;
height: 240px;
transform: rotate(45deg) skew(8deg,8deg);
position: absolute;
top: 42px;
}
.antzone [fox^=top] {
top: -151px;
background: #4fc4b2;
}
.antzone [fox^=right] {
left: 148px;
background:pink;
}
.antzone [fox^=bottom] {
bottom: -151px;
background:purple;
}
.antzone [fox^=left] {
right: 147px;
background:darkgoldenrod;
}
.antzone [fox=con]:hover [fox$=_c] {
transform: none;
width: 100%;
height: 100%;
top: 0;
left: 0;
}
.antzone [fox=con] [fox$=_c]:hover {
z-index: 5;
}
.antzone [fox$=_c] [fox$=_con] {
display: block;
width: calc((990px - 10px * 3) / 4);
height: calc((990px - 10px * 3) / 4 / 3 * 4);
background-image: linear-gradient(0deg,#4fc4b2,#fff,#b0fef2);
}
.antzone [fox^=top] [fox$=_con] {
transform: translateY(-100%);
}
.antzone [fox^=bottom] [fox$=_con] {
transform: translateY(100%);
}
.antzone [fox^=left] [fox$=_con] {
transform: translateX(-100%);
}
.antzone [fox^=right] [fox$=_con] {
transform: translateX(100%);
}
.antzone [fox$=_c]:hover [fox$=_con] {
transform: translateY(0);
transition: all .3s linear;
transform: translateX(0);
}
</style>
</head>
<body>
<div>
<div style="width:990px;margin:0 auto;">
<div class="antzone">
<div fox="con">
<div fox="top_c"><a fox="con_con"></a></div>
<div fox="right_c"><a fox="con_con"></a></div>
<div fox="bottom_c"><a fox="con_con"></a></div>
<div fox="left_c"><a fox="con_con"></a></div>
</div>
<div fox="con">
<div fox="top_c"><a fox="con_con"></a></div>
<div fox="right_c"><a fox="con_con"></a></div>
<div fox="bottom_c"><a fox="con_con"></a></div>
<div fox="left_c"><a fox="con_con"></a></div>
</div>
<div fox="con">
<div fox="top_c"><a fox="con_con"></a></div>
<div fox="right_c"><a fox="con_con"></a></div>
<div fox="bottom_c"><a fox="con_con"></a></div>
<div fox="left_c"><a fox="con_con"></a></div>
</div>
<div fox="con">
<div fox="top_c"><a fox="con_con"></a></div>
<div fox="right_c"><a fox="con_con"></a></div>
<div fox="bottom_c"><a fox="con_con"></a></div>
<div fox="left_c"><a fox="con_con"></a></div>
</div>
<div fox="con">
<div fox="top_c"><a fox="con_con"></a></div>
<div fox="right_c"><a fox="con_con"></a></div>
<div fox="bottom_c"><a fox="con_con"></a></div>
<div fox="left_c"><a fox="con_con"></a></div>
</div>
<div fox="con">
<div fox="top_c"><a fox="con_con"></a></div>
<div fox="right_c"><a fox="con_con"></a></div>
<div fox="bottom_c"><a fox="con_con"></a></div>
<div fox="left_c"><a fox="con_con"></a></div>
</div>
<div fox="con">
<div fox="top_c"><a fox="con_con"></a></div>
<div fox="right_c"><a fox="con_con"></a></div>
<div fox="bottom_c"><a fox="con_con"></a></div>
<div fox="left_c"><a fox="con_con"></a></div>
</div>
<div fox="con">
<div fox="top_c"><a fox="con_con"></a></div>
<div fox="right_c"><a fox="con_con"></a></div>
<div fox="bottom_c"><a fox="con_con"></a></div>
<div fox="left_c"><a fox="con_con"></a></div>
</div>
</div>
</div>
</div>
</body>
</html>
网友评论