😍
Framer API 中文版
  • 写在前面
  • 从这里开始
    • 介绍
      • 快速开始
      • 基础
    • 教程
      • 准备 Setup
      • 引入 Slider 组件
      • Slider组件的元素
      • 拖动 & MotionValue
      • Hooks & 传递数据
      • 完成
      • 回顾
    • 简要案例
      • Frame
      • Stack
      • Animate
      • Gestures
      • Dragging 拖拽
      • Scrolling 滚动
      • Paging 翻页
      • Tranforms 变换
      • Variants 动画状态组
  • LIBRARY 库
    • Frame
      • Layout 布局
      • Visual 视觉
      • Transform 变换
      • Animation 动画
      • Transition 过渡
      • Variants 动画状态组
      • Tap 点击
      • Hover 悬浮
      • Pan
      • Drag
      • Types
    • Animation
      • Overview
      • Animation controls
      • Tween
      • Spring
      • Inertia 惯性
      • Orchestration
      • Types
    • Color
      • Create
      • Modify
      • Convert
      • Compare
      • Models
    • Page
      • Content
      • Padding
      • Events
      • Effects
      • PageEffectInfo
    • Scroll
      • Sizing
      • Content
      • Events
    • Stack
      • Content
      • Padding
    • Utilities
      • Transfrom
      • useTransform
      • useAnimation
      • useCycle
      • useMotionValue
      • useSpring
      • useViewportScroll
  • FRAMER X
    • Assets
      • Functions
    • Data & Overrides
    • CanvasComponents
      • Canvas.tsx
      • Layout
      • Colors
    • PropertyControls
      • Adding Controls
      • Hiding Controls
      • Array
      • Boolean
      • Color
      • ComponentInstance
      • Enum
      • File
      • FusedNumber
      • Image
      • Number
      • SegmentedEnum
      • String
    • Render Target
      • Properties
      • Functions
Powered by GitBook
On this page

Was this helpful?

  1. 从这里开始
  2. 简要案例

Gestures

PreviousAnimateNextDragging 拖拽

Last updated 5 years ago

Was this helpful?

让我们实现一个当我们点击一个Frame标签让它产生变化的一个效果,我们首先要创建两个变量,一个是初始的rotate,它的初始值为0,一个是用来设置这个rotate变量的setRotate方法。

然后,创建一个函数toggleRotate,每次执行这个函数的时候,rotate变量里面的值就增加90。最后,我们把这个rotate变量传递到aimate这个属性里面,还要把toggleRotate这个函数绑定到onTap这个事件上。

import * as React from "react"
import { useState } from "react"
import { Frame } from "framer"

export function MyComponent() {
  const [rotate, setRotate] = useState(0)
  const toggleRotate = () => setRotate(rotate + 90)

  return <Frame animate={{ rotate }} onTap={toggleRotate} />
}

On Hover 鼠标悬停触发动画效果

现在,让我们实现一个当我们鼠标在Frame标签上会触发缩放的效果。我们可以使用whileHover属性来实现,给它传递一个scale属性及相应想要变化到的缩放比例的值。

import * as React from "react"
import { Frame } from "framer"

export function MyComponent() {
  return <Frame whileHover={{ scale: 0.75 }} />
}

Open Example
Open Example