UNPKG

jquery-infinite-scroller

Version:

A jQuery plugin that infinitely scrolls content based on mouse position

9 lines 1.73 kB
/* * jquery-infinite-scroller - v1.0.0 * A jQuery plugin that infinitely scrolls content based on mouse position * http://cawserve.com/jquery-infinite-scroller * * Made by Chris Watts * Under MIT License */ !function(a,b,c,d){"use strict";function e(b,c){this.element=b,this.settings=a.extend({},g,c),this.controller={currentSpeed:0},this.init()}var f="infiniteScroller",g={maxSpeed:20,speed:1,scrollOnMouseOver:!0,resetOnMouseOut:!0,direction:"left"};a.extend(e.prototype,{init:function(){var b=this.settings,c=a(this.element),d=c.wrapInner("<div class='slide-wrap'><div class='slide-data' /></div>").find(".slide-data"),e=c.find(".slide-wrap"),f=d.children("ul"),g=this.controller,h=b.speed;"right"===b.direction&&(h=-1*b.speed),c.addClass("slide-pane");var i=0;f.children().each(function(){a(this).height()>i&&(i=a(this).height())}),e.height(i),f.children().clone().appendTo(f);var j=0;f.children().each(function(){var b=a(this);b.css("left",j),j+=b.outerWidth(!0)});var k=j/2,l=d.width(),m=function(){var a=d.scrollLeft(),b=a+g.currentSpeed;b>2*k-l?b-=k:b<0&&(b+=k),d.scrollLeft(b)};setInterval(m,20),this.tweenToNewSpeed(h),b.scrollOnMouseOver&&this.scrollOnMouseOver(d)},tweenToNewSpeed:function(b,c){c===d&&(c=0),a(this.controller).stop(!0).animate({currentSpeed:b},c)},scrollOnMouseOver:function(c){var d=this.settings,e=this;c.mousemove(function(c){var f=a(b).width(),g=f/2,h=c.pageX,i=0,j=d.maxSpeed;i=h<g?-(100-(h/g*100).toFixed(2)):((h-g)/g*100).toFixed(2),j*=i/100,e.tweenToNewSpeed(j)}),d.resetOnMouseOut&&c.mouseout(function(){e.tweenToNewSpeed(d.speed,500)})}}),a.fn[f]=function(b){return this.each(function(){a.data(this,"plugin_"+f)||a.data(this,"plugin_"+f,new e(this,b))})}}(jQuery,window,document);