这是用户在 2024-4-3 17:39 为 https://github.com/choozn/react-parallax-mouse 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?
Skip to content
You have no unread notifications
choozn  /   react-parallax-mouse  /  
  • Watch 2

    Notifications

  • Lists

    Lists

Notifications

Notification settings

A lightweight react component to add a mouse parallax effect to your website.

License

Open in github.dev Open in a new github.dev tab Open in codespace

choozn/react-parallax-mouse

Repository files navigation

React Parallax Mouse React Parallax小鼠

❤️ A lightweight react component to add a mouse parallax effect to your website
一个轻量级的react组件,用于为您的网站添加鼠标视差效果。️

💚 Efficient and lag free animations optimized for performance
💚 针对性能优化的高效且无延迟动画

💙 Using react-spring under the hood for fluid animations
💙 在引擎盖下使用反作用力弹簧进行流体动画

🚀 Ready to use and provided with types
🚀 随时可用并提供类型

What is the Mouse Parallax Effect?
什么是老鼠视差效应?

➔ The parallax effect creates the illusion of depth when the cursor moves inside a specified container. The child of the container which is farthest from the user moves at the slowest speed, while the nearest child moves at the fastest speed.
视差效果在光标在指定容器内移动时创建深度错觉。容器中距离用户最远的子容器以最慢的速度移动,而最近的子容器以最快的速度移动。

It uses the mouse cursor position on the container and creates the illusion of depth for the layers visible in the container. For example, your cursor enters the container and the layers start to move away or approach to the cursor.
它使用鼠标光标在容器上的位置,并为容器中可见的层创建深度错觉。例如,光标进入容器,图层开始远离或接近光标。

(Read more at https://smartslider3.com/blog/parallax-effect/)
(Read更多信息请访问https://smartslider3.com/blog/billlax—effect/)

Example 例如

➔ An editable example can be found on CodeSandbox below.
可以在下面的CodeSandbox上找到一个可编辑的示例。

Edit react-parallax-mouse Example

Getting Started 开始

npm 南普

npm install react-parallax-mouse

yarn 斜纹纱

yarn add react-parallax-mouse

Usage 用法

import { MouseParallaxContainer, MouseParallaxChild } from "react-parallax-mouse";

The library provides you with two components and one hook.
该库提供了两个组件和一个钩子。

MouseParallaxContainer

➔ The main container in which the effect will take place. It provides a context for all of its children.
要发生效果的主要容器。它为所有儿童提供了一个环境。

MouseParallaxChild

➔ The layer component for the effect. It provides a container for all of its children, which will stay on the same layer. Only works within the MouseParallaxContainer component (as direct child or subchild).
默认效果的图层组件。它为所有子层提供了一个容器,这些子层将停留在同一层上。仅在组件内工作(作为直接子组件或子组件)。 MouseParallaxContainer

Example 例如

<MouseParallaxContainer globalFactorX={0.1} globalFactorY={0.1}>
  <MouseParallaxChild factorX={0.3} factorY={0.5}>
    <img src="example1.jpg" alt="" />
  </MouseParallaxChild>
  <MouseParallaxChild factorX={0.7} factorY={0.8}>
    <img src="example2.jpg" alt="" />
  </MouseParallaxChild>
</MouseParallaxContainer>

useParallaxOffset

➔ A hook that gives you direct access to the underlying spring and its values. It can be used to create custom child components.
一个钩子,让你直接访问底层的spring及其值。它可用于创建自定义子组件。

Example 例如

const { x, y } = useParallaxOffset();

Props 道具

➔ MouseParallaxContainer 产品展示

prop type description
enabled 启用 boolean (default: true) 布尔值(默认值:true) Enables or disables the effect.
启用或禁用效果。
globalFactorX number (default: 1) 数字(默认值:1) Strength multiplier of the effect on the X axis for every child component
每个子组件在X轴上的效果的强度乘数
globalFactorY 全球工厂 number (default: 1) 数字(默认值:1) Strength multiplier of the effect on the Y axis for every child component
每个子组件在Y轴上的效果的强度乘数
resetOnLeave boolean 布尔 Resets the view to 0:0 offset when the mouse leaves the container
当鼠标离开容器时,将视图重置为0:0偏移
useWindowMouseEvents boolean 布尔 Uses the window event handler instead of the container event handler to track mouse movement
使用窗口事件处理程序而不是容器事件处理程序来跟踪鼠标的移动
inverted 倒置 boolean 布尔 Inverts the offset of ParallaxChildren on mouse movement
反转鼠标移动时的偏移量 ParallaxChildren
containerStyle React.CSSProperties (Object)
React. CSSProperties(对象)
Additional CSS attributes which are applied directly to the parallax container element (equal to style on HTML elements)
直接应用于视差容器元素的附加CSS属性(等同于HTML元素) style
className string 字符串 The class name of the container
容器的类名
springConfig SpringConfig React Spring Config (https://react-spring.dev/common/configs)
React Spring Configuration(https://react—spring.dev/common/Adds)

➔ MouseParallaxChild 宠物宠物

prop type description
factorX (!) factorX(!) number Strength factor for the movement on the X axis
X轴上机芯的强度系数
factorY (!) factorY(!) number Strength factor for the movement on the Y axis
Y轴上运动的强度系数
inverted 倒置 boolean 布尔 Inverts the offset of the specific child element on mouse movement
在鼠标移动时反转特定子元素的偏移量
style 风格 React.CSSProperties (Object)
React. CSSProperties(对象)
Additional CSS attributes which are applied directly to the parallax child element (equal to style on HTML elements)
直接应用于视差子元素的附加CSS属性(等同于HTML元素) style
className string 字符串 The class name of the child
孩子的类名

🚀 https://github.com/choozn

© Copyright 2022 - @choozn
© 2022—2022—2019版权所有