11/*
2- 2017
3-
42Cute Scroll jQuery plugin by Merry Panda (https://github.com/MerryPanda)
53
64Inspired by Slim Scroll https://github.com/rochal/jQuery-slimScroll
7-
8- Version 1.1
95*/
106( function ( jq ) {
117 var util = { //utils
@@ -275,7 +271,7 @@ Version 1.1
275271 } ) ;
276272
277273 el . canvas . jq . on ( 'touchend.cs' , function ( e ) {
278- scroller . visibility . canBeHidden ( 'touch' ) ;
274+ scroller . visibility . canBeHidden ( ) ;
279275
280276 scroller . scrollByTouchSwipe ( touch . velocityGet ( ) , touch . getDelta ( ) ) ;
281277 } ) ;
@@ -360,13 +356,15 @@ Version 1.1
360356 noticer . setToDisabled ( ) ;
361357
362358 display . hide ( ) ;
359+
360+ operation . jumpToTop ( ) ;
363361 } ;
364362 function enable ( ) {
365363 noticer . setToEnabled ( ) ;
366364
367365 that . visibility . canBeHidden ( ) ;
368366
369- operation . barHeightApplyProportionalToContent ( ) ;
367+ operation . adjustPosition ( ) ;
370368
371369 if ( cfg . on . contentChangeShowScroller ) that . visibility . shouldBeShown ( ) ;
372370 } ;
@@ -483,14 +481,15 @@ Version 1.1
483481 var percentage ;
484482 //////
485483 this . wheelIteration = function ( ) {
486- return cfg . mouse . wheelStep / this . canvasMaxOffset ( ) * this . railHeight ( ) ;
484+ return cfg . mouse . wheelStep / this . canvasMaxOffset ( ) * this . areaHeight ( ) ;
487485 }
488486 this . touchIteration = function ( delta ) {
489- return cfg . touch . moveFactor * delta / this . canvasMaxOffset ( ) * this . railHeight ( ) ;
487+ return cfg . touch . moveFactor * delta / this . canvasMaxOffset ( ) * this . areaHeight ( ) ;
490488 }
491489 //////
492490 this . shouldItBeScrolled = function ( ) {
493- return this . canvasHeight ( ) > this . railHeight ( ) ? true : false ;
491+ //console.log('---shouldItBeScrolled',el.canvas.jq,Math.round(this.canvasHeight()),Math.round(this.railHeight()))
492+ return ( this . canvasHeight ( ) > this . areaHeight ( ) ) ? true : false ;
494493 } ;
495494 this . shouldItContinueToScrollPage = function ( ) {
496495 return ( this . isAtEdge ( ) && cfg . mouse . pageScroll ) ? true : false ;
@@ -503,16 +502,21 @@ Version 1.1
503502 }
504503 //////
505504 this . canvasHeight = function ( ) {
505+ //console.log('---canvasHeight',el.canvas.jq,el.canvas.js.scrollHeight,el.canvas.js.clientHeight)
506506 return el . canvas . js . scrollHeight ;
507507 }
508508 this . canvasMaxOffset = function ( ) {
509- return Math . abs ( this . canvasHeight ( ) - this . railHeight ( ) ) ;
509+ return Math . abs ( this . canvasHeight ( ) - this . areaHeight ( ) ) ;
510510 }
511511 this . canvasAdjustedPosition = function ( ) {
512512 return percentage * this . canvasMaxOffset ( ) ;
513513 }
514514 this . canvasVisibleProportion = function ( ) {
515- return Math . abs ( this . railHeight ( ) / this . canvasHeight ( ) ) ;
515+ return Math . abs ( this . areaHeight ( ) / this . canvasHeight ( ) ) ;
516+ }
517+ //////
518+ this . areaHeight = function ( ) {
519+ return el . canvas . js . clientHeight
516520 }
517521 //////
518522 this . railHeight = function ( ) {
@@ -564,18 +568,38 @@ Version 1.1
564568 function canvasMove ( i ) {
565569 el . canvas . jq . scrollTop ( i ) ;
566570 }
571+ function canvasAdjustToBar ( ) {
572+ canvasMove ( calc . canvasAdjustedPosition ( ) ) ;
573+ }
567574 function moveTo ( i ) {
568575 barMove ( i ) ;
569- canvasMove ( calc . canvasAdjustedPosition ( ) ) ;
576+ canvasAdjustToBar ( ) ;
570577 }
571578 //////
572579 this . move = function ( y ) {
573580 //console.log('--move',el.canvas.jq,calc.barMovementDistance(y),calc.canvasAdjustedPosition())
574581 moveTo ( calc . barMovementDistance ( y ) ) ;
575582 } ;
583+ /*
584+ this.canvasAdjustToBar=function(){
585+ //console.log('---canvasVisible',el.canvas.jq)
586+ canvasAdjustToBar();
587+ };
588+ */
589+ this . adjustPosition = function ( ) {
590+ //console.log('---barHeightApplyProportionalToContent',el.canvas.jq,el.canvas.js.scrollHeight,calc.barHeightProportionalToContent())
591+ if ( ! cfg . bar . height ) barHeightSet ( calc . barHeightProportionalToContent ( ) ) ;
592+
593+ this . move ( 0 ) ;
594+
595+ canvasAdjustToBar ( ) ;
596+ }
597+ /*
576598 this.barHeightApplyProportionalToContent=function(){
599+ console.log('---barHeightApplyProportionalToContent',el.canvas.jq,calc.barHeightProportionalToContent())
577600 if(!cfg.bar.height) barHeightSet(calc.barHeightProportionalToContent());
578601 }
602+ */
579603 this . jumpToTop = function ( ) {
580604 moveTo ( calc . barJumpToTop ( ) ) ;
581605 }
0 commit comments