动画效果合集
适度的动画可以提升交互的流畅感。以下片段为 Obsidian 添加各种微交互动画。
全局过渡
css
/* 全局平滑过渡 */
* {
transition: background-color 0.2s ease,
border-color 0.2s ease,
color 0.2s ease;
}按钮动画
css
/* 按钮悬停 */
button,
.clickable-icon {
transition: all 0.15s ease;
}
button:hover,
.clickable-icon:hover {
transform: translateY(-1px);
}链接动画
下划线滑入
css
a.internal-link {
position: relative;
text-decoration: none;
}
a.internal-link::after {
content: '';
position: absolute;
bottom: -2px;
left: 0;
width: 0;
height: 2px;
background: var(--interactive-accent);
transition: width 0.3s ease;
}
a.internal-link:hover::after {
width: 100%;
}背景高亮
css
.internal-link {
border-radius: 3px;
padding: 0 2px;
transition: background 0.2s;
}
.internal-link:hover {
background: rgba(124, 58, 237, 0.1);
}文件列表动画
css
/* 文件项悬停位移 */
.nav-file,
.nav-folder {
transition: all 0.15s ease;
}
.nav-file:hover,
.nav-folder:hover {
transform: translateX(2px);
}
/* 当前文件高亮 */
.nav-file.is-active {
transform: translateX(4px);
}列表入场动画
css
/* 列表项依次淡入 */
.markdown-preview-view ul li,
.markdown-preview-view ol li {
animation: fadeInUp 0.3s ease forwards;
opacity: 0;
}
.markdown-preview-view ul li:nth-child(1) { animation-delay: 0.05s; }
.markdown-preview-view ul li:nth-child(2) { animation-delay: 0.1s; }
.markdown-preview-view ul li:nth-child(3) { animation-delay: 0.15s; }
.markdown-preview-view ul li:nth-child(4) { animation-delay: 0.2s; }
.markdown-preview-view ul li:nth-child(5) { animation-delay: 0.25s; }
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(8px);
}
to {
opacity: 1;
transform: translateY(0);
}
}图片动画
css
/* 图片悬停放大 */
.markdown-preview-view img {
transition: transform 0.3s ease;
border-radius: 8px;
}
.markdown-preview-view img:hover {
transform: scale(1.02);
}Callout 动画
css
/* Callout 展开动画 */
.callout-content {
max-height: 0;
overflow: hidden;
transition: max-height 0.3s ease;
}
.callout:not(.is-collapsed) .callout-content {
max-height: 1000px;
}减少动画
css
/* 尊重用户减少动画偏好 */
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
animation-duration: 0.01ms !important;
transition-duration: 0.01ms !important;
}
}