1. 添加动态效果组件

  yarn add react-transition-group

2. 修改 src/common/header/index.js

import React, {Component} from 'react';

import {CSSTransition} from 'react-transition-group';

import {

HeaderWrapper,

Logo,

Nav,

NavItem,

SearchWrapper,

NavSearch,

Addtion,

Button

} from './style';

class Header extends Component{

constructor(props){

super(props);

this.state = {

focused : false

}

this.searchFocus = this.searchFocus.bind(this);

this.searchBlur = this.searchBlur.bind(this);

}

searchFocus(){

this.setState({

focused : true

})

}

searchBlur(){

this.setState({

focused : false

})

}

render(){

return (

<HeaderWrapper>

<Logo />

<Nav>

<NavItem className="left active">首页</NavItem>

<NavItem className="left">下载</NavItem>

<NavItem className="right">登陆</NavItem>

<NavItem className="right">

<span className="iconfont">&#xe601;</span>

</NavItem>

<SearchWrapper>

<CSSTransition

in={this.state.focused}

timeout={200}

classNames='slide'

>

<NavSearch

className={this.state.focused? 'focused' : ''}

onFocus={this.searchFocus}

onBlur={this.searchBlur}

></NavSearch>

</CSSTransition>

<span className={this.state.focused? 'focused iconfont' : 'iconfont'}>&#xe60b;</span>

</SearchWrapper>

</Nav>

<Addtion>

<Button className='writting'>

<span className="iconfont">&#xe703;</span>

写文章

</Button>

<Button className='reg'>注册</Button>

</Addtion>

</HeaderWrapper>

);

}

}

export default Header;

3. 修改 src/common/header/style.js

引入 slide-enter  ,   slide-enter-active , slide-exit , slide-exit-active

import styled from 'styled-components';

import LogoPic from '../../statics/logo.png';

export const HeaderWrapper = styled.div`

postition: relate;

height:56px;

border-bottom:1px solid #f0f0f0;

`;

export const Logo = styled.a.attrs({

href : '/'

})`

position: absolute;

left : 0;

top : 0;

display: block;

height:56px;

width:100px;

background: url(${LogoPic}) no-repeat;

background-size: contain;

`;

export const Nav = styled.div`

width:960px;

box-size: box-size;

padding-right: 70px;

height: 56px;

margin-left: 100px;

`

export const NavItem = styled.div`

&.left {

float: left;

}

&.right {

float: right;

color: #969696;

}

&.active {

color: #ea6f5a;

}

line-height: 56px;

front-size: 15px;

padding-left: 6px;

padding-right: 12px;

color: #333;

`;

export const SearchWrapper = styled.div`

float: left;

position: relative;

.iconfont {

position: absolute;

right: 5px;

bottom: 5px;

width: 30px;

line-height:30px;

border-radius : 15px;

text-align:center;

&.focused{

background : #777;

color : #fff;

}

}

`;

export const NavSearch = styled.input.attrs({

placeholder : '搜索'

})`

width : 160px;

height : 38px;

border: none;

outline : none;

padding : 0 35px 0 20px;

box-size: box-size;

margin-top: 9px;

margin-left: 20px;

border-radius : 19px;

background: #eee;

font-size: 14px;

&::placeholder{

color: #999;

}

&.focused{

width: 200px;

}

&.slide-enter {

width: 160px;

transition: all .2s ease-out;

}

&.slide-enter-active {

width: 200px;

}

&.slide-exit {

width: 200px;

transition: all .2s ease-out;

}

&.slide-exit-active {

width: 160px;

}

`;

export const Addtion = styled.div`

position:absolute;

right: 0;

top: 0;

height: 65px;

`;

export const Button = styled.div`

float:right;

line-height:38px;

margin-top:9px;

margin-right: 20px;

border-radius: 19px;

border : 1px solid rgba(236,97,73,.7);

color : #fff;

padding : 0 20px;

&.reg{

color:#ea6f5a;

}

&.writting{

background:#ea6f5a;

}

`;

3 react 简书 添加 头部搜索动态效果的更多相关文章

  1. react 简书开发笔记

    详见文章<React简书开发实战课程笔记>

  2. 2. react 简书 头部(header) 图标添加

    1. 访问 iconfont 并注册 登陆 2. 进入 iconfont 头部 图标管理->我的项目 3. 点击右边的文件夹 + 号 图标 创建我的项目 输入项目名称即可 4.在 搜索框 搜索 ...

  3. 2. react 简书 头部 (header) 样式编写

    1. 在 src 下 创建 common 文件下 创建 header 文件夹下 创建 index.js #src/common/header/index.js import React, {Compo ...

  4. React 简书

    create-react-app   jianshu yarn add styled-components -D       利用js写css样式  样式会更高效 https://github.com ...

  5. 4 react 简书 引入 redux 的 combineReducers 对 redux 数据进行管理

    1. src 下的 common 下的 header 创建 store 文件夹 下创建 reducer.js # src/common/header/store/reducer.js const st ...

  6. react简书

    开发项目之前的准备 https://www.chromefor.com/  登录此网站 下载相关crx react插件 不然要FQ 下载 React Developer Tools 谷歌插件下载 Re ...

  7. react简书笔记一 环境, git 和 项目 关联

    1.. 建立git项目  ( 码云, github 都可以 ), 具体步骤: https://www.cnblogs.com/andy-lehhaxm/p/10720717.html 1.1  git ...

  8. 1. react 简书 项目初始化

    1. 创建 react 项目 npx create-react-app my-app 2. src 目录下删除 除了 index.js index.css app.js 的文件 3. 引入 style ...

  9. vue添加滚动事件,解决简书Carol_笑一笑方案中vue移除滚动事件失效的问题

    在写项目的时候,遇到了需要添加滚动事件的问题,在简书Carol_笑一笑这里找到了解决方案.代码如下 <script> export default { name:"vue-scr ...

随机推荐

  1. 39数组中只出现一次的数字+判断的时候一定加上括号,&的优先级低于!=

    题目描述 一个整型数组里除了两个数字之外,其他的数字都出现了两次.请写程序找出这两个只出现一次的数字.     思路:记住位运算的基本操作,与或非,异或,异或是两个数相同则为0,不同为1,理解为加法运 ...

  2. MySQL日常使用笔记

    逍遥山人的MySQL使用笔记,持续更新中 表结构 新建表以及添加表和字段的注释 create table t_user( ID INT(11) primary key auto_increment c ...

  3. 关于c++ 感想

    前言 在学校开展了c++的课程,但是不得不说相当乏味. 原因很简单: 1.感觉c++很高级,自己就这智商怎么学的会哦,自己给了自己门槛. 2.c++很难快速的做出一个能够展现的项目,缺乏成就感. 3. ...

  4. javascript if else优化指南

    不管是平时在学习js中还是在项目书中写js代码,都避免不了一个问题就是有时候要做大量的分支判断,很多人的第一反应就是使用if else.无可厚非,if else早平时做分支判断的时候是非常好用的,但是 ...

  5. 4K对齐

    4K对齐这个概念常常与固态硬盘联系起来.买了一块固态硬盘,装机过程中时有忽略4K对齐这个小细节,但是这个小细节往往十分重要,它影响硬盘的使用寿命和速度. 现在来了解一下4K对齐到底是个什么东西. 一. ...

  6. 使用zabbix server监控tomcat实战案例

    使用zabbix server监控tomcat实战案例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 大家都知道,zabbix server效率高是使用C语言编写的,有很多应用程序 ...

  7. 2.13 阶段实战 使用layui重构选课系统

    一.说在前面   昨天  学习表单校验插件validate,并使用ajax 自定义校验规则   今天 使用layui重构选课系统 二.题目要求 1.项目需求: 本项目所开发的学生选课系统完成学校对学生 ...

  8. CCF 201703-4 地铁修建(最小生成树)

    题意:A市有n个交通枢纽,其中1号和n号非常重要,为了加强运输能力,A市决定在1号到n号枢纽间修建一条地铁.地铁由很多段隧道组成,每段隧道连接两个交通枢纽.经过勘探,有m段隧道作为候选,两个交通枢纽之 ...

  9. Helm 架构【转】

    在实践之前,我们先来看看 Helm 的架构. Helm 有两个重要的概念:chart 和 release. chart 是创建一个应用的信息集合,包括各种 Kubernetes 对象的配置模板.参数定 ...

  10. Codeforces 591 B:Rebranding

    B. Rebranding time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...