0

I do hope this question makes sense! I'm working on a site using the code from this answer: https://stackoverflow.com/a/28097928

I'd like to apply a really basic/short fade-in transition so that the changing text doesn't flash as quickly and appears less jarring. How would I do that? How do I know which attribute to apply the transition to?

EDIT: jsfiddle link

This is the basic Javascript in place:

<script>
function hover(description) {
console.log(description);
document.getElementById('content').innerHTML = description;
}
</script>

Any advice would be greatly appreciated!

Thank you!

3
  • may be you can apply CSS animation rules along with the change. Commented Jun 10, 2016 at 19:53
  • You'll likely get a better response if you create a jsfiddle that can be played with. Commented Jun 10, 2016 at 19:55
  • Certainly! A link has been added. Commented Jun 10, 2016 at 20:10

1 Answer 1

2

I hope you don't mind I added some CSS.

This will add a fade in transition.

function hover(description) {

            console.log(description);
            document.getElementById('content').className = null;
            setTimeout(function(){
                document.getElementById('content').className = 'transitionedText';
                document.getElementById('content').innerHTML = description;
            },100);
        }
@keyframes textTransition{
        0%{
            opacity: 0;
        }
        100%{
            opacity: 1;
        }
    }
    #content{
        color: #000;
        opacity: 0;
    }
    #content.transitionedText{
        animation-name: textTransition;
        animation-duration: 1000ms;
        animation-fill-mode: forwards;
        color: red;
    }
<div id="content">
            Stuff should be placed here.
        </div>
        <br/>
        <br/>
        <br/>
        <ul>
            <li onmouseover="hover('Apples are delicious')">Apple</li>
            <li onmouseover="hover('oranges are healthy')">Orange</li>
            <li onmouseover="hover('Candy is the best')">Candy</li>
        </ul>

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I don't know a ton about keyframes, so this isn't a solution I would ever have thought of. Much appreciated!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.