<html lang="en">
<head>
<meta charset="utf-8">
<title>Failing Focus in Animated UI</title>
</head>
<body>
<article id="example-introduction">
<h1>Failing Focus in Animated UI</h1>
<p>This example shows the basic concept of a carousel, accordion and similar content-revealing UI widgets.</p>
<p>
The buttons reveal their associated slides by using the CSS properties <code>transform</code> and <code>transition</code>.
The checkbox controls if focus should be shifted to the slide as it is revealed.
</p>
<p>Note how shifting focus interferes with the content being presented, because of the browser scrolling elements into view when they become the active element.</p>
</article>
<div id="example-html">
<main>
<section data-active-item="first">
<fieldset>
<legend>show slide</legend>
<p>
<button type="button" data-show="first">first</button>
<button type="button" data-show="second">second</button>
<button type="button" data-show="third">third</button>
</p>
<p>
<label><input type="checkbox" id="with-focus"> shift focus to slide</label>
</p>
<p>
<button type="button" id="reset">reset scroll position</button>
</p>
</fieldset>
<div id="cropper">
<ul>
<li id="first" tabindex="-1">First</li>
<li id="second" tabindex="-1">Second</li>
<li id="third" tabindex="-1">Third</li>
</ul>
</div>
</section>
</main>
</div>
</body>
</html>
main p {
margin: 0;
}
main p + p {
margin-top: 10px;
}
#cropper {
width: 200px;
border: 1px solid black;
margin-top: 10px;
overflow: hidden;
}
section ul {
box-sizing: border-box;
width: 600px;
border: 1px solid grey;
margin: 0;
padding: 0;
list-style: none;
display: flexbox;
display: flex;
display: flex;
flex-direction: row;
flex-direction: row;
flex-direction: row;
flex-wrap: nowrap;
flex-wrap: nowrap;
flex-wrap: nowrap;
justify-content: center;
flex-pack: center;
justify-content: center;
align-content: stretch;
flex-line-pack: stretch;
align-content: stretch;
align-items: stretch;
flex-align: stretch;
align-items: stretch;
transition: transform 1s ease-in-out;
}
section[data-active-item="first"] ul {
transform: translate3d(0px, 0px, 0px);
}
section[data-active-item="second"] ul {
transform: translate3d(-200px, 0px, 0px);
}
section[data-active-item="third"] ul {
transform: translate3d(-400px, 0px, 0px);
}
section[data-active-item="first"] #first,
section[data-active-item="second"] #second,
section[data-active-item="third"] #third {
visibility: inherit;
transition: visibility 0s 0s linear;
}
section ul li {
display: flex;
box-sizing: border-box;
width: 200px;
padding: 20px;
margin: 0;
visibility: hidden;
transition: visibility 0s 1s linear;
}
#first {
background: #ccccff;
}
#second {
background: #ccffcc;
}
#third {
background: #ffcccc;
}
var section = document.querySelector('section');
var withFocus = document.getElementById('with-focus');
section.addEventListener('click', function(event) {
var id = event.target.getAttribute('data-show');
if (!id) {
return;
}
// transition to slide
section.setAttribute('data-active-item', id);
if (withFocus.checked) {
// shift focus to slide
document.getElementById(id).focus();
}
}, true);
var cropper = document.getElementById('cropper');
var reset = document.getElementById('reset');
reset.addEventListener('click', function() {
cropper.scrollLeft = 0;
}, true);
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |