<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
* {
margin: 0;padding: 0;
}
#div1 {
position: relative;
width: 712px;
height: 108px;
margin: 50px auto;
overflow: hidden;
background: red;
}
#div1 ul {
position: absolute;
left: 0;
top: 0;
transition: .3s ease-out;
}
#div1 ul li {
float: left;
width: 178px;
height: 108px;
list-style: none;
}
</style>
<script>
window.onload = function () {
var oDiv = document.getElementById('div1');
var oUl = oDiv.getElementsByTagName('ul')[0];
var aLi = oUl.getElementsByTagName('li');
oUl.style.width = aLi[0].offsetWidth * aLi.length + 'px';
function moveRight() {
if(oUl.offsetLeft >= 0) {
oUl.style.left = -(aLi.length-4)*178 + 'px';
return true;
}
oUl.style.left = oUl.offsetLeft + 178 + 'px';
}
function moveLeft() {
if(oUl.offsetLeft <= -(aLi.length-4)*178) {
oUl.style.left = '0px';
return true;
}
oUl.style.left = oUl.offsetLeft - 178 + 'px';
}
document.getElementsByTagName('a')[0].onclick = function() {
setTimeout(moveLeft);
};
document.getElementsByTagName('a')[1].onclick = function() {
setTimeout(moveRight);
};
}
</script>
</head>
<body>
<a href="javascript:;">向左走</a>
<a href="javascript:;">向右走</a>
<div id="div1">
<ul>
<li><img src="http://placekitten.com/g/200/300" alt=""/></li>
<li><img src="http://placekitten.com/g/200/300" alt=""/></li>
<li><img src="http://placekitten.com/g/200/300" alt=""/></li>
<li><img src="http://placekitten.com/g/200/300" alt=""/></li>
<li><img src="http://placekitten.com/g/200/300" alt=""/></li>
<li><img src="http://placekitten.com/g/200/300" alt=""/></li>
<li><img src="http://placekitten.com/g/200/300" alt=""/></li>
</ul>
</div>
</body>
</html>
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. |