一、行走的线条。

  • 效果图(加载可能会慢一点儿,请稍等...):

  • html代码:
 <div class="movingLines">
<img src="data:images/ser2.jpg" alt=""><!-- 背景图片-->
<div class="cover cover2"><!-- 遮盖层-->
<div class="innerBor"> <!--四根线条-->
<p class="topHr"/>
<p class="rightHr"/>
<p class="leftHr"/>
<p class="bottomHr"/>
</div> <div class="content"><!-- 遮盖层内容 -->
<img class="serIcon" src="data:images/ser_pre2.png" alt="">
<h6><a href="">家具与软装顾问</a></h6>
<p>除了家居设计,特别推出空间软装布置顾问,2对1全程指导,为您提供功能于色彩建议、配饰与摆设建议,杜绝爱巢变成“杂货铺”</p>
</div>
</div>
</div>
  • 思路一:先不要管线条的动画效果,首先分析出静态的布局,将遮盖层与底层布局完成,调试好层级关系和位置关系。通过定位使得 .content 遮盖层和 .innerBor 都位于整个div的中间部分,并且是重合的。
  • css样式:
.movingLines {
width: 350px;
height: 246px;
position: relative;
}
 /*背景图片*/
.movingLines img{ width: 100%; height: 100%; }
/*遮盖层*/
.movingLines .cover2{
        width: 100%;
height: 100%;
position: absolute;
top:0px;
left: 0px;
text-align: center;
transition: all .5s linear;
background: #6DD3D1;
} .movingLines .innerBor{ width: 90%;
height: 90%;
position: absolute;
top: 5%;
left: 5%;
display: block;
border: 1px solid #747474;
transition: all .5s linear; } .movingLines .content{
width: 90%;
height: 90%;
position: absolute;
top: 5%;
left: 5%;
text-align: center;
background: red;
}
  • 思路二:当思路一种的布局弄好以后,遮盖层中的.innerBor是位于.content的底层的。由于.content静态的时候就存在外边框的,但是鼠标浮动的时候,这个边框依然是存在的,但是不能直接给.content 加边框,因为.innerBor是位于它的下一层,不论怎么修改底层的东西,都不可能遮盖上一级的内容。所以这个静态的边框线一定是.innerBor的,并且是border,而不是outline(这里不赘述二者的区别)。由于二者是同样的大小,并且没有设定overflow:hidden,这样给.innerBor加 border的时候,边框线就会在content的非遮盖范围内,就可以看见了。
  • 思路三:这下只需要给innerBor加上移动的线条就行了。怎么加?不可能使用border,因为它已经被静态的页面占用了,就算没有占用,css里面也没有适合的api.换一个思路,这四根线像不像只有1px的四个div,在不断的增加高度或者宽度?是的没错,但是html中不建议使用空的div,所以把其改成p标签,让其display:block;就是一个块元素了,就可以改变宽高了。
  • 思路四:将其定位到四个角的位置。注意:起始位置。此外由于所有的p标签都位于.innerBor的内部,所以定位的时候定位位置是-1px;这样才能遮盖住border。
  • css代码
.movingLines .topHr{
display: block;
position: absolute;
top: -1px;
right:;
width: 0%;
height: 1px;
background: white;
transition: all .5s linear;
} .movingLines .rightHr{
display: block;
position: absolute;
top:;
right:-1px;
width: 1px;
height: 0%;
background: white;
transition: all .5s linear;
} .movingLines .bottomHr{
display: block;
position: absolute;
bottom: -1px;
left:;
width:;
height: 1px;
background: white;
transition: all .5s linear;
} .movingLines .leftHr{
display: block;
position: absolute;
bottom:;
left:-1px;
width: 1px;
height: 0%;
background: white;
transition: all .5s linear;
}
  • 思路五:添加鼠标浮动事件,不废话了直接上代码
.movingLines:hover .topHr{
width: 100%;
transition: all .5s linear;
} .movingLines:hover .rightHr{
height: 100%;
transition: all .5s linear;
} .movingLines:hover .bottomHr{
width: 100%;
transition: all .5s linear;
} .movingLines:hover .leftHr{
height: 100%;
transition: all .5s linear;
} .movingLines:hover .cover{
background: rgba(0,0,0,.7);
transition: all .5s linear;
}
  • 完整的css代码:不仅有改变四根线的动画代码,还有改变遮盖层的透明度、遮盖层中文字内容放大缩小、透明度的动画代码,图片放大缩小、平移的代码。是不是很全?
 .movingLines {
width: 350px;
height: 246px;
position: relative;
} .movingLines img{
width: 100%;
height: 100%;
}
.movingLines .cover2{
width: 100%;
height: 100%;
position: absolute;
top:0px;
left: 0px;
text-align: center;
transition: all .5s linear;
background: #6DD3D1;
} .movingLines .innerBor{ width: 90%;
height: 90%;
position: absolute;
top: 5%;
left: 5%;
display: block;
border: 1px solid #747474;
transition: all .5s linear; } .movingLines .content{
width: 90%;
height: 90%;
position: absolute;
top: 5%;
left: 5%;
text-align: center;
background: red;
} .movingLines .topHr{
display: block;
position: absolute;
top: -1px;
right:;
width: 0%;
height: 1px;
background: white;
transition: all .5s linear;
} .movingLines .rightHr{
display: block;
position: absolute;
top:;
right:-1px;
width: 1px;
height: 0%;
background: white;
transition: all .5s linear;
} .movingLines .bottomHr{
display: block;
position: absolute;
bottom: -1px;
left:;
width:;
height: 1px;
background: white;
transition: all .5s linear;
} .movingLines .leftHr{
display: block;
position: absolute;
bottom:;
left:-1px;
width: 1px;
height: 0%;
background: white;
transition: all .5s linear;
} .movingLines .serIcon{
width: 40px;
height: 40px;
margin-top: 60px;
transition: all .5s linear;
}
.movingLines h6 {
transition: all .5s linear;
}
.movingLines h6 a{
color: white;
font-size: 16px; }
.movingLines .content p{
opacity:;
font-size: 14px;
transform: scale(0,0);
transition: all .5s linear; } .movingLines:hover .serIcon{
transform: translateY(-30px) scale(.5,.5);
transition: all .5s linear;
} .movingLines:hover h6{
transform: translateY(-30px);
transition: all .5s linear;
}
.movingLines:hover p{
opacity:;
transform: scale(1,1);
transition: all .5s linear;
}
.movingLines:hover .topHr{
width: 100%;
transition: all .5s linear;
} .movingLines:hover .rightHr{
height: 100%;
transition: all .5s linear;
} .movingLines:hover .bottomHr{
width: 100%;
transition: all .5s linear;
} .movingLines:hover .leftHr{
height: 100%;
transition: all .5s linear;
} .movingLines:hover .cover{
background: rgba(0,0,0,.7);
transition: all .5s linear;
} .movingLines .cover:hover span{
animation: service_span_anim 1s linear forwards;
} @keyframes service_span_anim{
from{border-width: 1px;border-color: #000;}
to{border-width: 0px;border-color: red;}
}
二、置顶导航栏
  • 效果图(加载可能会慢一点儿,请稍等...):

  • html代码和css代码就不提供了,大家可以写一个<header></header> 设置它的宽100%和高80px,加一个背景色模拟一个简单的导航栏就行了。
  • 思路:导航栏原本只是静态的在一个特定的位置,并且背景为(background:transparent;)透明的。但随着滑动鼠标,会固定到顶部和回到原来的位置。
  • 说明:这里面,不仅涉及到固定定位还涉及到对滚动条的监听,因为是根据滚动条的位置来设定导航栏的的位置的。这里需要使用一些js来实现,我采用的是非原生的js----jquery,不知道的小伙伴自行查阅资料(友情链接:http://www.runoob.com/jquery/jquery-tutorial.html)。
  • 呈上js代码:
$(function(){

    var isToTop = false;//设置一个标记,来记录导航栏是否位于顶部
$(window).scroll(function(){
var scrollTop = $(this).scrollTop();//获取滚动条
if(scrollTop>80&&!isToTop){//当滚动条的高度大于80px,并且导航栏不是位于顶部的时候,通过jq给header添加css样式使其固定定位到浏览器可视窗口的顶部
$("header").css({
"position":"fixed",
"top":"0",
"background":"rgb(51,51,51)",
"transition":"all .5s linear"
}); isToTop = true;
}
//当滚动条的高度小于80px,并且导航栏是位于顶部的时候,通过jq给header添加css样式使其回到原始的位置。
if(scrollTop<80&&isToTop){
$("header").css({
"position":"absolute",
"top":"40px",
"background":"transparent",
"transition":"all .5s linear"
});
isToTop = false;
}
});
});
  • 其实这个案例只要懂得用js获取滚动条对象,并获取其高度。以及会用js给html页面元素添加css样式,就可以实现。js是不是很强大?快学起来吧。

css3特效第二篇--行走的线条&&置顶导航栏的更多相关文章

  1. [知了堂学习笔记]_css3特效第二篇--行走的线条&&置顶导航栏

    一.行走的线条. 效果图(加载可能会慢一点儿,请稍等...): html代码: <div class="movingLines"> <img src=" ...

  2. css3特效第一篇--旋转的背景&翻书效果

    一.html遮盖层与css3的旋转动画 >效果图(加载可能会慢一点儿,请稍等...): >实现思路:在一个大的div中装入一个底层img和顶层的div(里面的内容按照以上图片呈现的样式布局 ...

  3. nginx基础学习第二篇:nginx内置变量的使用

    ngx_http_core模块提供的内置变量有很多,常见的有 $uri,用来获取当前请求的uri,不含请求参数. $request_uri,用来获取请求最原始的uri,包含请求参数,且未解码. $re ...

  4. CSS3——对齐 组合选择符 伪类 伪元素 导航栏 下拉菜单

     水平&垂直对齐 元素居中对齐 .center { margin: auto; width: 50%; border: 3px solid green; padding: 10px; } 文本 ...

  5. CSS3 特效分解一

    先声明下,下面的特效不是我发明的,对CSS3的创造力还不够,只是看了别人demo的源码,一点一点分析出来的.整理出的笔记,分享给大家.因为源码是好,但是一头扎进去半天出不来. 首先看个登陆框,如下,相 ...

  6. [置顶] android利用jni调用第三方库——第二篇——编写库android程序直接调用第三方库libhello.so

    0:前言 1:本文主要作为丙方android公司的身份来写 2:作者有不对的地方,请指出,谢谢 [第一篇:android利用jni调用第三方库——编写库libhello.so] [第二篇:androi ...

  7. 深入理解javascript对象系列第二篇——属性操作

    × 目录 [1]查询 [2]设置 [3]删除[4]继承 前面的话 对于对象来说,属性操作是绕不开的话题.类似于“增删改查”的基本操作,属性操作分为属性查询.属性设置.属性删除,还包括属性继承.本文是对 ...

  8. [转]Android开源项目第二篇——工具库篇

    本文为那些不错的Android开源项目第二篇--开发工具库篇,主要介绍常用的开发库,包括依赖注入框架.图片缓存.网络相关.数据库ORM建模.Android公共库.Android 高版本向低版本兼容.多 ...

  9. 第二篇.Bootstrap起步

    第二篇Bootstrap起步 我们可以在http://getbootstrap.com下载bootstrap的文件 点击左边的download bootstrap可以下载bootstrap的css,j ...

随机推荐

  1. spring boot的几种配置类型

    1.spring boot的几种配置类型 1)基本配置,spring自动读取的,全都在application.yml里配置,spring会自动读取这个配置文件 2)个性化配置:比如配置intercep ...

  2. Oracle的JDBC Url的几种方式

    1.普通SID方式jdbc:oracle:thin:username/password@x.x.x.1:1521:SID2.普通ServerName方式 jdbc:Oracle:thin:userna ...

  3. Android nomedia 避免图片等资源泄露在系统图库其中

    总结 Android nomedia 避免文件泄露在系统图库和系统铃声中 在应用开发中 项目的图片总是被系统的图库收录了 避免图片被系统图库收录的发现有2个方法 第一种针对图片 将 .png为后缀的图 ...

  4. 数据结构(Java语言)——LinkedList简单实现

    下面是一个能够使用的LinkedList泛型类的实现.这里的链表类名为MyLinkedList,避免与类库中反复. MyLinkedList将作为双链表实现,并且保留到该表两端的引用.这样仅仅要操作发 ...

  5. Android - 加入Android的OpenCV依赖库(Android Dependencies) 问题

    加入Android的OpenCV依赖库(Android Dependencies) 问题 本文地址: http://blog.csdn.net/caroline_wendy 假设想要加入OpenCV的 ...

  6. Foundation框架经常使用数据类型和NSAutoreleasePool自己主动释放池解析

    第一.NSAutoreleasePool自己主动释放池解析 1.自己主动释放池的物理实现 自己主动释放池用栈来实现.当你创建一个新的自己主动释放池是,会压栈到栈顶.接受autorelease消息的对象 ...

  7. 0x28 IDA*

    一个早上做完了我真牛B 就是A*用于DFS啊,现在我才发现迭代加深真是个好东西. poj3460 %了%了我们的目标是把它的顺序变对,那么第i个位置的值+1是要等于第i+1个位置的值的.对于一个操作, ...

  8. pyspark MLlib踩坑之model predict+rdd map zip,zip使用尤其注意啊啊啊!

    Updated:use model broadcast, mappartition+flatmap,see: from pyspark import SparkContext import numpy ...

  9. JSP页面动态查询添加数据与分页数据显示

    1 . <%@ page language="java" contentType="text/html; charset=UTF-8"%> < ...

  10. idea设置Template

    在eclipse里面经常会用到syso和main类似这样的内容,但是idea工具里面没有,可以通过 Editor ==> Live templates  ==> 1.首先创建一个自己的Te ...