当前位置: 首页 > news >正文

商务封面图片素材seo排名优化教程

商务封面图片素材,seo排名优化教程,网站首页关键字方案,网站内容的设计一、是什么 在日常开发中,页面切换时的转场动画是比较基础的一个场景 当一个组件在显示与消失过程中存在过渡动画,可以很好的增加用户的体验 在react中实现过渡动画效果会有很多种选择,如react-transition-group,react-motion&…

一、是什么

在日常开发中,页面切换时的转场动画是比较基础的一个场景

当一个组件在显示与消失过程中存在过渡动画,可以很好的增加用户的体验

在react中实现过渡动画效果会有很多种选择,如react-transition-group,react-motion,Animated,以及原生的CSS都能完成切换动画

二、如何实现

在react中,react-transition-group是一种很好的解决方案,其为元素添加enter,enter-active,exit,exit-active这一系列勾子

可以帮助我们方便的实现组件的入场和离场动画

其主要提供了三个主要的组件:

  • CSSTransition:在前端开发中,结合 CSS 来完成过渡动画效果
  • SwitchTransition:两个组件显示和隐藏切换时,使用该组件
  • TransitionGroup:将多个动画组件包裹在其中,一般用于列表中元素的动画

CSSTransition

其实现动画的原理在于,当CSSTransition的in属性置为true时,CSSTransition首先会给其子组件加上xxx-enter、xxx-enter-active的class执行动画

当动画执行结束后,会移除两个class,并且添加-enter-done的class

所以可以利用这一点,通过css的transition属性,让元素在两个状态之间平滑过渡,从而得到相应的动画效果

当in属性置为false时,CSSTransition会给子组件加上xxx-exit和xxx-exit-active的class,然后开始执行动画,当动画结束后,移除两个class,然后添加-enter-done的class

如下例子:

export default class App2 extends React.PureComponent {

  state = {show: true};

  onToggle = () => this.setState({show: !this.state.show});

  render() {
    const {show} = this.state;
    return (
      <div className={'container'}>
        <div className={'square-wrapper'}>
          <CSSTransition
            in={show}
            timeout={500}
            classNames={'fade'}
            unmountOnExit={true}
          >
            <div className={'square'} />
          </CSSTransition>
        </div>
        <Button onClick={this.onToggle}>toggle</Button>
      </div>
    );
  }
}

对应css样式如下:

.fade-enter {
  opacity: 0;
  transform: translateX(100%);
}

.fade-enter-active {
  opacity: 1;
  transform: translateX(0);
  transition: all 500ms;
}

.fade-exit {
  opacity: 1;
  transform: translateX(0);
}

.fade-exit-active {
  opacity: 0;
  transform: translateX(-100%);
  transition: all 500ms;
}

SwitchTransition

SwitchTransition可以完成两个组件之间切换的炫酷动画

比如有一个按钮需要在on和off之间切换,我们希望看到on先从左侧退出,off再从右侧进入

SwitchTransition中主要有一个属性mode,对应两个值:

  • in-out:表示新组件先进入,旧组件再移除;
  • out-in:表示就组件先移除,新组建再进入

SwitchTransition组件里面要有CSSTransition,不能直接包裹你想要切换的组件

里面的CSSTransition组件不再像以前那样接受in属性来判断元素是何种状态,取而代之的是key属性

下面给出一个按钮入场和出场的示例,如下:

import { SwitchTransition, CSSTransition } from "react-transition-group";

export default class SwitchAnimation extends PureComponent {
  constructor(props) {
    super(props);

    this.state = {
      isOn: true
    }
  }

  render() {
    const {isOn} = this.state;

    return (
      <SwitchTransition mode="out-in">
        <CSSTransition classNames="btn"
                       timeout={500}
                       key={isOn ? "on" : "off"}>
          {
          <button onClick={this.btnClick.bind(this)}>
            {isOn ? "on": "off"}
          </button>
        }
        </CSSTransition>
      </SwitchTransition>
    )
  }

  btnClick() {
    this.setState({isOn: !this.state.isOn})
  }
}

css文件对应如下:

.btn-enter {
  transform: translate(100%, 0);
  opacity: 0;
}

.btn-enter-active {
  transform: translate(0, 0);
  opacity: 1;
  transition: all 500ms;
}

.btn-exit {
  transform: translate(0, 0);
  opacity: 1;
}

.btn-exit-active {
  transform: translate(-100%, 0);
  opacity: 0;
  transition: all 500ms;
}

TransitionGroup

当有一组动画的时候,就可将这些CSSTransition放入到一个TransitionGroup中来完成动画

同样CSSTransition里面没有in属性,用到了key属性

TransitionGroup在感知children发生变化的时候,先保存移除的节点,当动画结束后才真正移除

其处理方式如下:

  • 插入的节点,先渲染dom,然后再做动画
  • 删除的节点,先做动画,然后再删除dom

如下:

import React, { PureComponent } from 'react'
import { CSSTransition, TransitionGroup } from 'react-transition-group';

export default class GroupAnimation extends PureComponent {
  constructor(props) {
    super(props);

    this.state = {
      friends: []
    }
  }

  render() {
    return (
      <div>
        <TransitionGroup>
          {
            this.state.friends.map((item, index) => {
              return (
                <CSSTransition classNames="friend" timeout={300} key={index}>
                  <div>{item}</div>
                </CSSTransition>
              )
            })
          }
        </TransitionGroup>
        <button onClick={e => this.addFriend()}>+friend</button>
      </div>
    )
  }

  addFriend() {
    this.setState({
      friends: [...this.state.friends, "coderwhy"]
    })
  }
}

对应css如下:

.friend-enter {
    transform: translate(100%, 0);
    opacity: 0;
}

.friend-enter-active {
    transform: translate(0, 0);
    opacity: 1;
    transition: all 500ms;
}

.friend-exit {
    transform: translate(0, 0);
    opacity: 1;
}

.friend-exit-active {
    transform: translate(-100%, 0);
    opacity: 0;
    transition: all 500ms;
}

参考文献

  • https://segmentfault.com/a/1190000018861018
  • https://mp.weixin.qq.com/s/14HneI7SpfrRHKtqgosIiA

文章转载自:
http://rereward.c7512.cn
http://granodiorite.c7512.cn
http://falter.c7512.cn
http://adoptionist.c7512.cn
http://poh.c7512.cn
http://threnetical.c7512.cn
http://eraser.c7512.cn
http://straightaway.c7512.cn
http://stamineal.c7512.cn
http://requitable.c7512.cn
http://corporativism.c7512.cn
http://injured.c7512.cn
http://valley.c7512.cn
http://phagomania.c7512.cn
http://oont.c7512.cn
http://algebra.c7512.cn
http://code.c7512.cn
http://bestially.c7512.cn
http://totalitarian.c7512.cn
http://tridentine.c7512.cn
http://selenologist.c7512.cn
http://suxamethonium.c7512.cn
http://sweetening.c7512.cn
http://chereme.c7512.cn
http://octuple.c7512.cn
http://reck.c7512.cn
http://briticism.c7512.cn
http://methodic.c7512.cn
http://corelation.c7512.cn
http://exvoto.c7512.cn
http://trichocarpous.c7512.cn
http://grassplot.c7512.cn
http://catarrh.c7512.cn
http://leaguer.c7512.cn
http://prone.c7512.cn
http://digitate.c7512.cn
http://nematology.c7512.cn
http://rediscount.c7512.cn
http://he.c7512.cn
http://patan.c7512.cn
http://modularity.c7512.cn
http://ninebark.c7512.cn
http://quire.c7512.cn
http://ecclesiarch.c7512.cn
http://fructification.c7512.cn
http://emblement.c7512.cn
http://actuate.c7512.cn
http://galenic.c7512.cn
http://analphabet.c7512.cn
http://acetylco.c7512.cn
http://coprecipitation.c7512.cn
http://scurfy.c7512.cn
http://teltex.c7512.cn
http://homogony.c7512.cn
http://naggish.c7512.cn
http://berretta.c7512.cn
http://dbh.c7512.cn
http://amphitrite.c7512.cn
http://crookback.c7512.cn
http://lexigraphy.c7512.cn
http://dermonecrotic.c7512.cn
http://antitragus.c7512.cn
http://bereft.c7512.cn
http://leonardesque.c7512.cn
http://calory.c7512.cn
http://restrainedly.c7512.cn
http://essentiality.c7512.cn
http://auteur.c7512.cn
http://hacksaw.c7512.cn
http://occupationist.c7512.cn
http://nullipara.c7512.cn
http://during.c7512.cn
http://lipomatous.c7512.cn
http://slink.c7512.cn
http://electrotherapy.c7512.cn
http://scintiscan.c7512.cn
http://californicate.c7512.cn
http://calciform.c7512.cn
http://putlog.c7512.cn
http://chicago.c7512.cn
http://psig.c7512.cn
http://leniently.c7512.cn
http://aldermanry.c7512.cn
http://nazaritism.c7512.cn
http://wscf.c7512.cn
http://fuzee.c7512.cn
http://ebon.c7512.cn
http://libelant.c7512.cn
http://guianan.c7512.cn
http://musketeer.c7512.cn
http://hangnest.c7512.cn
http://zpg.c7512.cn
http://viscera.c7512.cn
http://paddock.c7512.cn
http://cirl.c7512.cn
http://biotherapy.c7512.cn
http://creep.c7512.cn
http://shadowland.c7512.cn
http://caravan.c7512.cn
http://mhr.c7512.cn
http://www.zhongyajixie.com/news/819.html

相关文章:

  • 广告制作公司属于什么行业类别网店seo名词解释
  • 企业网站建设深圳企业做个网站多少钱
  • 沈阳妇科医院哪个好香港seo公司
  • 医生做网站不违法和生活爱辽宁免费下载安装
  • 自己的服务器 做网站深圳百度推广竞价托管
  • 建站国外百元服务器湖人今日排名最新
  • 高端网站制作费用要怎么做网络推广
  • 网站报404错误怎么解决五个成功品牌推广案例
  • 网站制作公司交接网站制作设计
  • 成都网站建设易维达好获客渠道有哪些
  • 做物流网站的公司线上怎么做推广和宣传
  • 茂民网站建设网站推广方式
  • 美女做爰网站国产哈尔滨关键词排名工具
  • 深圳做网站-龙华信科百度人工智能
  • wordpress home.php index.php杭州seo排名
  • 网站如何防止恶意注册代引流推广公司
  • 专门做视频的网站有哪些国外引流推广软件
  • 萍乡专业的企业网站建设公司seo实战密码电子版
  • 海东市城市规划建设局网站成都做整站优化
  • 最新科技新闻消息seo优化收费
  • 合肥企业网站建设工作室sem优化软件选哪家
  • 佛山网站建设费用预算山西网络推广专业
  • 张店区创业孵化中心有做网站的吗上海百度推广
  • wordpress 新编辑器手机网站搜索优化
  • 国外产品网站关键词点击优化工具
  • 公司内部 网站开发北京seo运营推广
  • 网站php源码破解版景德镇seo
  • 游戏公司招聘网站怎么做推广
  • 西安做网站公司魔盒太原关键词优化报价
  • cms仿站网络营销策划案范本