<html>
<head>
<title>jQuery scrolling tab demo.</title>
<link rel="stylesheet" href="reset.css">
<link rel="stylesheet" href="style.css">
</head>
<body>
<section>
<div class="scrolling">
<div class="scrollbarLine"></div>
<div class="scrollbar"></div>
<h1>Sed lectus.</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. <img src="http://media.idownloadblog.com/wp-content/uploads/2014/08/Yosemite-2-wallpaper-thumbnail.png"/>Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero.</p>
<p>But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?</p>
</div>
</section>
<script src="https://code.jquery.com/jquery-2.2.1.min.js"></script>
<script src="https://github.com/jquery/jquery-mousewheel/blob/master/jquery.mousewheel.min.js"></script>
<script src="tab.js"></script>
</body>
</html>
$(function() {
var scrollingTab = $('.scrolling');
var marginTop = 0;
scrollingTab.on('mouseenter', function() {
$(this).find('.scrollbar').animate({'opacity': 1}, 200);
$(this).find('.scrollbarLine').animate({'opacity': 0.3}, 200);
}).on('mouseleave', function() {
$(this).find('.scrollbar').animate({'opacity': 0}, 200);
$(this).find('.scrollbarLine').animate({'opacity': 0}, 200);
});
scrollingTab.on('mousewheel', function() {
var realMargin = parseInt($(this).css('margin-top'));
if (Math.abs(marginTop-realMargin) < 40 ) {
console.log($(this).h);
var deltaY;
var textHeight = parseInt($(this).css('height'));
var viewHeight = parseInt($(this).parent().css('height'));
var workingHeight = textHeight - viewHeight;
var progress;
var bar = $(this).find('.scrollbar');
var speed;
deltaY = event.deltaY > 0 ? -160 : 160;
marginTop += deltaY;
marginTop = marginTop < -workingHeight ? -workingHeight : marginTop;
marginTop = marginTop > 0 ? 0 : marginTop;
if (marginTop !== realMargin) {
speed = 200 / Math.abs(deltaY) * Math.abs(marginTop-realMargin);
$(this).animate({'margin-top' : marginTop}, speed, 'linear');
progress = (viewHeight-26)/100*(marginTop/((workingHeight)/100));
bar.animate({'top': 24-progress}, speed, 'linear');
}
}
});
});
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. |