I don't have a good enough understanding of web development to be able to tell if my question is already answered here, so apologies if this is a duplicate.
I'm planning to have a lot of different pages in my website, all structured differently, all of which need to look reasonable on a variety of different screen sizes. These pages will include and/or link-to code that makes various bits of content appear and disappear. On some of these pages however I'm finding there's too much appearing and disappearing all at once and the reader gets confused about exactly what has changed. To solve this, I'd love to write either some CSS or some JS for ensuring that when the position of an element changes, it smoothly moves into the new position instead of just jumping there. Hopefully, this will help the end-user better understand how the content has changed.
I'm currently trying to do this with CSS using a "transition" applied to the "position" attribute, but to no avail. Here's the code:
function toggleVisibility(elementId) {
var element = document.getElementById(elementId);
if (element.style.display === "none") {
element.style.display = null;
} else {
element.style.display = "none";
}
}
#lol {
position: relative;
transition: position 2s;
transition-timing-function: linear;
-webkit-transition-timing-function: linear;
}
<head>
<title>Title</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id="foo"> foo </div>
<div id="bar"> bar </div>
<div id="lol"> lol </div>
<button onmouseup="toggleVisibility('bar')"> Click me</button>
</body>
This doesn't do anything helpful, unfortunately. There's no smooth transition; the text that says "lol" jumps around instantaneously.
Ideas, anyone? A javascript solution is fine, but I'm looking for something that's generic enough that it can be applied anywhere on the page without precomputing any values, if that makes sense.