useCurrentScale()v4.0.125
使用这个钩子,你可以获取画布的缩放因子。 如果你想测量 DOM 节点,这很有用。
🌐 With this hook, you can retrieve the scale factor of the canvas.
Useful for if you want to measure DOM nodes.
在工作室中,它将对应缩放级别——如果缩放为100%,其值为1。
在播放器中,它将对应需要将视频画布适应播放器的缩放比例。
🌐 In the Studio, it will correspond to the zoom level - the value is 1 if the zoom is at 100%.
In the Player, it will correspond to the scale that is needed to fit the video canvas in the Player.
MyComp.tsximport {Sequence ,useCurrentScale } from 'remotion'; constMyVideo = () => { constscale =useCurrentScale (); return <div >The current scale is {scale }</div >; };
如果你在 Remotion 上下文之外使用,该钩子将抛出错误。
如果你想避免此错误并返回默认缩放值,你可以传递一个选项对象,并将属性 dontThrowIfOutsideOfRemotion 设置为 true。
在这种情况下,钩子将返回 1。
🌐 If you are outside of a Remotion context, the hook will throw an error.
If you want to avoid this error and return a default scale, you can pass an options object with the property dontThrowIfOutsideOfRemotion set to true.
In this case, the hook will return 1.
MyComp.tsximport {useCurrentScale } from 'remotion'; constMyRegularReactComponent = () => { constscale =useCurrentScale ({dontThrowIfOutsideOfRemotion : true}); return <div >The current scale is {scale }</div >; };
兼容性
🌐 Compatibility
| Browsers | Servers | Environments | |||||||
|---|---|---|---|---|---|---|---|---|---|
Chrome | Firefox | Safari | Node.js | Bun | Serverless Functions | ||||
Returns 1 | Returns 1 | Returns 1 | Returns 1 | Returns 1 | |||||
另请参阅
🌐 See also