useCurrentScale()v4.0.125
使用此钩子,您可以检索画布的缩放因子。
如果您想要测量 DOM 节点,这将非常有用。
在Studio中,它将对应于缩放级别 - 如果缩放为 100%,则值为 1
。
在Player中,它将对应于需要将视频画布适配到播放器中所需的比例。
MyComp.tsxtsx
import {Sequence ,useCurrentScale } from "remotion";constMyVideo = () => {constscale =useCurrentScale ();return <div >The current scale is {scale }</div >;};
MyComp.tsxtsx
import {Sequence ,useCurrentScale } from "remotion";constMyVideo = () => {constscale =useCurrentScale ();return <div >The current scale is {scale }</div >;};
如果您不在 Remotion 上下文之外,该钩子将引发错误。
如果您想避免此错误并返回默认比例,您可以传递一个带有属性 dontThrowIfOutsideOfRemotion
设置为 true
的选项对象。
在这种情况下,该钩子将返回 1
。
MyComp.tsxtsx
import {useCurrentScale } from "remotion";constMyRegularReactComponent = () => {constscale =useCurrentScale ({dontThrowIfOutsideOfRemotion : true });return <div >The current scale is {scale }</div >;};
MyComp.tsxtsx
import {useCurrentScale } from "remotion";constMyRegularReactComponent = () => {constscale =useCurrentScale ({dontThrowIfOutsideOfRemotion : true });return <div >The current scale is {scale }</div >;};