As explained in this answer, usign the option fragile of the frame disallow the use overlays, as an alternative you can use ampersand replacement=\& to overcome errors.
ps: I saw the trick of visible on somewhere here.
The following code preserve the positions of the arrows labels after switching the arrows position, the switching is accomplished step by step (one arrow at a time) with same order of apperance.
\documentclass{beamer}
\usepackage{tikz-cd}
\tikzset{
invisible/.style={opacity=0},
visible on/.style={alt={#1{}{invisible}}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}%
}
}
\begin{document}
\begin{frame}
\begin{tikzcd}[ampersand replacement=\&]
A \arrow[visible on=<2-5>]{r}{e} \arrow[visible on=<5-8>]{d}[swap]{f} \&
\arrow[visible on=<6->]{l}[swap]{e} B \arrow[visible on=<3-6>]{d}{g} \\
\arrow[visible on=<9->]{u}{f} C \arrow[visible on=<4-7>]{r}[swap]{h} \&
\arrow[visible on=<8->]{l}[swap]{h} D \arrow[visible on=<7->]{u}[swap]{g}
\end{tikzcd}
\end{frame}
\end{document}
The order of the commands is important to ensure the second part of the question (about shifting the arrows direction) without having errors.
If you want to switch label positions too replace with this code fragment:
\begin{tikzcd}[ampersand replacement=\&]
A \arrow[visible on=<2-5>]{r}{e} \arrow[visible on=<5-8>]{d}[swap]{f} \&
\arrow[visible on=<6->]{l}{e} B \arrow[visible on=<3-6>]{d}{g} \\
\arrow[visible on=<9->]{u}[swap]{f} C \arrow[visible on=<4-7>]{r}[swap]{h} \&
\arrow[visible on=<8->]{l}[swap]{h} D \arrow[visible on=<7->]{u}{g}
\end{tikzcd}
- Switch arrows direction all at the same time, and keeping the labels position outside (if you want to invert them too use/remove
[swap] depending on the arrow position).
Code:
\documentclass{beamer}
\usepackage{tikz-cd}
\tikzset{
invisible/.style={opacity=0},
visible on/.style={alt={#1{}{invisible}}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}%
}
}
\begin{document}
\begin{frame}
\begin{tikzcd}[ampersand replacement=\&]
A \arrow[visible on=<2-5>]{r}{e} \arrow[visible on=<5>]{d}[swap]{f} \&
\arrow[visible on=<6->]{l}[swap]{e} B \arrow[visible on=<3-5>]{d}{g} \\
\arrow[visible on=<6->]{u}{f} C \arrow[visible on=<4-5>]{r}[swap]{h} \&
\arrow[visible on=<6->]{l}{h} D \arrow[visible on=<6->]{u}[swap]{g}
\end{tikzcd}
\end{frame}
\end{document}
The same here if you want to switch label positions, replace with this ocde fragment:
\begin{tikzcd}[ampersand replacement=\&]
A \arrow[visible on=<2-5>]{r}{e} \arrow[visible on=<5>]{d}[swap]{f} \&
\arrow[visible on=<6->]{l}{e} B \arrow[visible on=<3-5>]{d}{g} \\
\arrow[visible on=<6->]{u}[swap]{f} C \arrow[visible on=<4-5>]{r}[swap]{h} \&
\arrow[visible on=<6->]{l}[swap]{h} D \arrow[visible on=<6->]{u}{g}
\end{tikzcd}