JQuery Thumbnail Scroller without Plugin

http://www.dte.web.id/2012/09/thumbnail-scroller.html

by Taufik Nurrohman

HTML

<div class="t-s">
    <div class="t-c">
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
    </div>
</div>
<div class="t-s">
    <div class="t-c">
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
    </div>
</div>
<div class="t-s">
    <div class="t-c">
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
    </div>
</div>

CSS

body {
    background-color:white;
    padding:50px 50px 60px;
    margin:0;
}
.t-s {
    border:1px solid black;
    height:50px;
    margin:10px 10px 0;
    overflow:auto;
}
.t-c {
    overflow:hidden;
    height:40px;
    margin:5px 0 0 0;
    position:relative;
}
.t-c p {
    margin:0;
    padding:0;
    width:50px;
    height:40px;
    background-color:#bbb;
    float:left;
    margin-left:5px;
}

JavaScript

(function ($) {

    $('.t-s').each(function () {

        var $thumbnailScroller = $(this),
            $container = $thumbnailScroller.find('.t-c'),
            $item = $container.children(),
            item_length = $item.length,
            item_width = $item.outerWidth(true),
            total_width = item_width * item_length,
            $window = $(window);

        $thumbnailScroller.css('overflow', 'hidden');
        $container.css('width', total_width);

        $window.on("resize", function () {
            var o_l = $thumbnailScroller.offset().left,
                t_w = $thumbnailScroller.width(),
                c_w = total_width;
            $thumbnailScroller.off().on("mousemove", function (e) {
                if ($(this).width() < $container.width()) {
                    $container.css('left', -((e.pageX - o_l) * ((c_w - t_w) / t_w)));
                }
            });
        }).trigger("resize");

    });

})(jQuery);