Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<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="http://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

Dismiss x
public
Bin info
anonymouspro
0viewers