
复制自 twitter 上的@jhey [!注意] 这假设您已经设置了暗光模式,并具有某种功能来更新您的主题
/* angled */
[data-style='angled']::view-transition-old(root) {
animation: none;
z-index: -1;
}
[data-style='angled']::view-transition-new(root) {
animation: unclip 1s;
clip-path: polygon(-100vmax 100%, 100% 100%, 100% -100vmax);
}
@keyframes unclip {
0% {
clip-path: polygon(100% 100%, 100% 100%, 100% 100%);
}
}
useeffect(() => {
// set the data-style attribute
document.documentelement.dataset.style = "angled";
}, []);
在ssr中可以直接在html标签中设置
function transitioncolors() {
if (typeof window !== "undefined") {
document.startviewtransition(() => {
const newtheme = theme === "light" ? "dark" : "light";
document.documentelement.dataset.theme = newtheme;
updatetheme(newtheme);
});
}
}
可以通过包含相应的 css 文件并添加正确的 data-style 属性来添加更多过渡样式
<select
className="select select-bordered select-sm max-w-xs"
onChange={(e) =>
(document.documentElement.dataset.style = e.target.value)
}
>
<option value="default">Default</option>
<option value="vertical">Vertical</option>
<option value="wipe">Wipe</option>
<option value="angled">Angled</option>
<option value="flip">Flip</option>
<option value="slides">Slides</option>
</select>
反应示例
如果你喜欢这种类型的 css 技巧,请考虑关注 jhey
以上就是查看过渡主题动画的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号