0

I am not able to add A transition to this Javascript function.

function togglediv(id) {
    var div = document.getElementById(id);
    div.style.display = div.style.display == "none" ? "block" : "none";
}
3
  • As you used the css-transitions tag, did you try to Google "css transition via javascript"? Commented May 11, 2016 at 7:11
  • Can you post your html too? How are you call your togglediv function. Commented May 11, 2016 at 7:17
  • Working Demo Commented May 11, 2016 at 7:38

1 Answer 1

1

The display property cannot be animated.

What you could do is fade in/out by animate opacity. Add a css class 'out' which is defined like

.out {
    opacity: 0;
    transition: opacity 1s;
}

See https://jsfiddle.net/s42stnyw/2/

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

Comments

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.