How to change text color in different fragments
Asked Answered
O

4

12

Say I have a simple reveal.js slide like this:

 <section>
   <h1>Title</h1>
   <p >Text</p>
   <p class="fragment">Fragment</p>
 </section>

I'd like to change Text colour to red after Fragment appears on screen. How should I do it?

Ogdoad answered 29/10, 2013 at 11:56 Comment(0)
H
6

It's not rather simple:

<section>
  <h1>Title</h1>
  <p id="postfragment">Text</p>
  <p class="fragment">Fragment</p>
</section>
...
<script>
Reveal.addEventListener('fragmentshown', function(event) {
   document.getElementById("postfragment").style.color="red"; 
});
</script>
Hippel answered 29/10, 2013 at 12:3 Comment(0)
C
14

You could simply do

<section>
  <h1>Title</h1>
  <p class="fragment highlight-red" data-fragment-index="1" >Text</p>
  <p class="fragment data-fragment-index="1"">Fragment</p>
</section>

That way, the red text and the "Fragment" text will always be in sync.

Cherin answered 12/11, 2013 at 21:30 Comment(0)
H
6

It's not rather simple:

<section>
  <h1>Title</h1>
  <p id="postfragment">Text</p>
  <p class="fragment">Fragment</p>
</section>
...
<script>
Reveal.addEventListener('fragmentshown', function(event) {
   document.getElementById("postfragment").style.color="red"; 
});
</script>
Hippel answered 29/10, 2013 at 12:3 Comment(0)
H
2

For those who want the highlight to actually appear after (rather than at the same time):

<section>
    <h1>Title</h1>
    <span class="fragment fade-in" data-fragment-index="1">
        <p class="fragment highlight-red" data-fragment-index="3">Text</p>
    </span>
    <p class="fragment" data-fragment-index="2">Fragment</p>
</section>
Hardiman answered 7/9, 2018 at 18:4 Comment(0)
M
0

Here is a sample of how to do it with red blue and green

<p>Highlight <span class="fragment highlight-red">red</span> <span class="fragment highlight-blue">blue</span> <span class="fragment highlight-green">green</span></p>
Macy answered 12/4, 2019 at 8:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.