# How to highlight a line of text (with colored background) with animation in beamer?

There are several ways to highlight a line of text with colored background in beamer, for example, using framed or mdframed.

How to animate this highlight, i.e., filling the background color from left to right? (You can use any packages as you will.)

Scenario: You first list a few points, and then (e.g., after a \pause) you emphasize one of them by (progressively) highlighting it.

\documentclass{beamer}
\usepackage{framed, color}
\usepackage{mdframed}

\begin{document}
\begin{frame}
A piece of shaded text with red background for highlight.

\begin{mdframed}[backgroundcolor = yellow]
A piece of mdframed text with yellow background for highlight.
\end{mdframed}
\end{frame}
\end{document}


An animate-based version:

\documentclass{beamer}

\usepackage{color}
\usepackage{calc}
\usepackage{animate}

\begin{document}
\begin{frame}

\begin{itemize}
\item on first
\item<2-> on second
\alt<3>{\item
\begin{animateinline}[autoplay]{24}
\multiframe{26}{n=0.0+0.04}{
\makebox[\widthof{\colorbox{yellow}{on third we see something magical}}][l]{%
\colorbox{yellow}{\makebox[\n\width][l]{on third we see something magical}}%
}
}
\end{animateinline}
}{\item<4->
\colorbox{yellow}{on third we see something magical}
}
\item<4-> on fourth
\end{itemize}

\end{frame}

\end{document}


You could create such an animation with tikz:

\documentclass{beamer}

\usepackage{tikz}

\begin{document}
\begin{frame}
\transduration{0}
\begin{tikzpicture}
\foreach \foreach \x in {0,0.01, ...,1}{
\fill<+>[red] (0,0) rectangle (\x*\textwidth,1);
}
\node[anchor=west] at (0.25,0.5) {A piece of text with red background for highlight.};
\end{tikzpicture}
\end{frame}
\end{document}