X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2F20_ui%2F15_ScrollBox.js;h=e82a647c8036482834b8ca7d95c9cd54d1be6d35;hb=HEAD;hp=f7d334bdcd117afacda07ff0e3080e94877f0f61;hpb=f74335422a0ae2d66e3ce9bfa03f0c77a107e8d1;p=pettanr%2FclientJs.git diff --git a/0.6.x/js/20_ui/15_ScrollBox.js b/0.6.x/js/20_ui/15_ScrollBox.js index f7d334b..e82a647 100644 --- a/0.6.x/js/20_ui/15_ScrollBox.js +++ b/0.6.x/js/20_ui/15_ScrollBox.js @@ -3,51 +3,81 @@ * ScrollManager * indicatorX, Y は再利用 */ -var XUI_ScrollBox_current, +var XUI_ScrollBox_useCSSP = !X_UA[ 'IE5' ], + XUI_ScrollBox_current, XUI_ScrollBox_indicatorV, XUI_ScrollBox_indicatorH; function XUI_ScrollBox_start( scrollBox ){ // 既存スクロールの停止 - if( scrollBox.hasVScroll ){ + if( XUI_ScrollBox_current && XUI_ScrollBox_current !== scrollBox ){ + XUI_ScrollBox_indicatorV && + XUI_ScrollBox_current[ 'unlisten' ]( [ X_EVENT_CANCELED, XUI_Event.SCROLL_END ], XUI_ScrollBox_indicatorV, XUI_ScrollBox_indicatorHandleEvent ); + + XUI_ScrollBox_indicatorH && + XUI_ScrollBox_current[ 'unlisten' ]( [ X_EVENT_CANCELED, XUI_Event.SCROLL_END ], XUI_ScrollBox_indicatorH, XUI_ScrollBox_indicatorHandleEvent ); + }; + + if( scrollBox && scrollBox.hasVScroll ){ if( !XUI_ScrollBox_indicatorV ){ XUI_ScrollBox_indicatorV = X_Doc_create( 'div' )[ 'className' ]( 'ScrollBox-IndicatorV' ); - }; - scrollBox.xnode[ 'append' ]( XUI_ScrollBox_indicatorV ); - XUI_ScrollBox_indicatorV[ 'animate' ]( - { opacity : 0 }, - { opacity : 1 }, - 900, 'circular', 300 - ); - scrollBox - [ 'listenOnce' ]( [ X_EVENT_CANCELED, XUI_Event.SCROLL_END ], XUI_ScrollBox_indicatorV, XUI_ScrollBox_indicatorHandleEvent ); + if( scrollBox.xnode !== XUI_ScrollBox_indicatorV.parent ){ + console.log( '*** Scroll Indicator add ***' ); + scrollBox.xnode[ 'append' ]( XUI_ScrollBox_indicatorV ); + XUI_ScrollBox_indicatorV[ 'animate' ]({ + 'from' : { opacity : 0 }, + 'to' : { opacity : 0.5 }, + 'duration' : 900, + 'easing' : 'circular', + 'lazyRelease' : 300 + }); + scrollBox + [ 'listen' ]( [ X_EVENT_CANCELED, XUI_Event.SCROLL_END ], XUI_ScrollBox_indicatorV, XUI_ScrollBox_indicatorHandleEvent ); + }; + } else + if( XUI_ScrollBox_indicatorV ){ + console.log( '*** Scroll Indicator remove ***' ); + XUI_ScrollBox_indicatorV[ 'remove' ](); }; - if( scrollBox.hasHScroll ){ + + if( scrollBox && scrollBox.hasHScroll ){ if( !XUI_ScrollBox_indicatorH ){ XUI_ScrollBox_indicatorH = X_Doc_create( 'div' )[ 'className' ]( 'ScrollBox-IndicatorH' ); }; - scrollBox.xnode[ 'append' ]( XUI_ScrollBox_indicatorH ); - XUI_ScrollBox_indicatorH[ 'animate' ]( - { opacity : 0 }, - { opacity : 1 }, - 900, 'circular', 300 - ); - scrollBox - [ 'listenOnce' ]( [ X_EVENT_CANCELED, XUI_Event.SCROLL_END ], XUI_ScrollBox_indicatorH, XUI_ScrollBox_indicatorHandleEvent ); + if( scrollBox.xnode !== XUI_ScrollBox_indicatorH.parent ){ + scrollBox.xnode[ 'append' ]( XUI_ScrollBox_indicatorH ); + XUI_ScrollBox_indicatorH[ 'animate' ]({ + 'from' : { opacity : 0 }, + 'to' : { opacity : 0.5 }, + 'duration' : 900, + 'easing' : 'circular', + 'lazyRelease' : 300 + }); + scrollBox + [ 'listen' ]( [ X_EVENT_CANCELED, XUI_Event.SCROLL_END ], XUI_ScrollBox_indicatorH, XUI_ScrollBox_indicatorHandleEvent ); + }; + } else + if( XUI_ScrollBox_indicatorH ){ + XUI_ScrollBox_indicatorH[ 'remove' ](); }; + + XUI_ScrollBox_current = scrollBox; }; function XUI_ScrollBox_indicatorHandleEvent( e ){ + //if( !XUI_ScrollBox_useCSSP ) return; switch( e.type ){ case X_EVENT_CANCELED : case XUI_Event.SCROLL_END : console.log( '-fadeout-' ); - this[ 'animate' ]( - { opacity : 1 }, - { opacity : 0 }, - 900, 'circular', 300 - ); + this[ 'animate' ]({ + 'from' : { opacity : 0.5 }, + 'to' : { opacity : 0 }, + 'duration' : 900, + 'easing' : 'circular', + 'lazyRelease' : 300 + }); break; }; }; @@ -185,7 +215,11 @@ var XUI_ScrollBox = XUI_ChromeBox.inherits( XUI_rootData[ 'unlisten' ]( XUI_Event.LAYOUT_COMPLETE, this, X_UI_ScrollBox_onLayoutComplete ); this[ 'unlisten' ]( XUI_Event.SCROLL_END, XUI_rootData, XUI_rootData.calculate ); - this.xnodeSlider[ 'stop' ](); + XUI_ScrollBox_useCSSP ? this.xnodeSlider[ 'stop' ]() : this.xnode[ 'stop' ](); + + XUI_ScrollBox_current === this && XUI_ScrollBox_start( null ); + + this.scrolling = false; }; } @@ -193,13 +227,13 @@ var XUI_ScrollBox = XUI_ChromeBox.inherits( ); function X_UI_ScrollBox_onLayoutBefore( e ){ - if( e[ 'cancelable' ] && this.isInTransition && X_Node_Anime_translateZ ){ + if( e[ 'cancelable' ] && this.isInTransition && X_NodeAnime_translateZ ){ this[ 'listenOnce' ]( XUI_Event.SCROLL_END, XUI_rootData, XUI_rootData.calculate ); return X_CALLBACK_PREVENT_DEFAULT; }; this.scrollXRatio = this.scrollX / this.scrollXMax; this.scrollYRatio = this.scrollY / this.scrollYMax; - this.xnodeSlider[ 'stop' ](); + XUI_ScrollBox_useCSSP ? this.xnodeSlider[ 'stop' ]() : this.xnode[ 'stop' ](); this.isInTransition = false; return X_CALLBACK_NONE; }; @@ -269,24 +303,43 @@ function X_UI_ScrollBox_translate( that, x, y, opt_time, opt_easing, opt_release opt_easing = opt_easing === '' ? '' : opt_easing || 'circular'; opt_release = 0 <= opt_release ? opt_release : 300; - that.xnodeSlider[ 'animate' ]( - { - x : that.scrollX, - y : that.scrollY - }, - { - x : x, - y : y - }, - opt_time, opt_easing, opt_release - ); + console.log( 'scr ' + y ); + + if( !XUI_ScrollBox_useCSSP ){ + that.xnode[ 'animate' ]({ + 'from' : { + scrollX : -that.scrollX, + scrollY : -that.scrollY + }, + 'to' : { + scrollX : -x, + scrollY : -y + }, + 'duration' : opt_time, + 'easing' : opt_easing + }); + } else { + that.xnodeSlider[ 'animate' ]({ + 'from' : { + x : that.scrollX, + y : that.scrollY + }, + 'to' : { + x : x, + y : y + }, + 'duration' : opt_time, + 'easing' : opt_easing, + 'lazyRelease' : opt_release + }); + }; if( X_UA[ 'IE' ] < 6 ){ XUI_ScrollBox_indicatorV && XUI_ScrollBox_indicatorV[ 'css' ]( 'left', ( scrollBoxW - that.fontSize * 0.6 | 0 ) + 'px' ); XUI_ScrollBox_indicatorH && XUI_ScrollBox_indicatorH[ 'css' ]( 'top' , ( scrollBoxH - that.fontSize * 0.6 | 0 ) + 'px' ); }; - if( that.hasVScroll && XUI_ScrollBox_indicatorV ){ + if( that.hasVScroll && XUI_ScrollBox_indicatorV && XUI_ScrollBox_indicatorV.parent === that.xnode ){ indicatorH = scrollBoxH * scrollBoxH / ( - that.scrollYMax + scrollBoxH ); scrollBoxH -= indicatorH; @@ -294,34 +347,36 @@ function X_UI_ScrollBox_translate( that, x, y, opt_time, opt_easing, opt_release [ 'css' ]({ height : ( indicatorH | 0 ) + 'px' }) - [ 'animate' ]( - { - y : scrollBoxH * that.scrollY / that.scrollYMax - }, - { - y : scrollBoxH * y / that.scrollYMax, - opacity : 1 - }, - opt_time, opt_easing, opt_release - ); - }; - if( that.hasHScroll && XUI_ScrollBox_indicatorH ){ + [ 'animate' ]({ + 'from' : { + y : scrollBoxH * that.scrollY / that.scrollYMax }, + 'to' : { + y : scrollBoxH * y / that.scrollYMax, + opacity : 0.5 + }, + 'duration' : opt_time, + 'easing' : opt_easing, + 'lazyRelease' : opt_release + }); + }; + if( that.hasHScroll && XUI_ScrollBox_indicatorH && XUI_ScrollBox_indicatorH.parent === that.xnode ){ indicatorW = scrollBoxW * scrollBoxW / ( - that.scrollXMax + scrollBoxW ); scrollBoxW -= indicatorW; XUI_ScrollBox_indicatorH [ 'css' ]({ width : ( indicatorW | 0 ) + 'px' }) - [ 'animate' ]( - { - x : scrollBoxW * that.scrollX / that.scrollXMax - }, - { - x : scrollBoxW * x / that.scrollXMax, - opacity : 1 - }, - opt_time, opt_easing, opt_release - ); + [ 'animate' ]({ + 'from' : { + x : scrollBoxW * that.scrollX / that.scrollXMax }, + 'to' : { + x : scrollBoxW * x / that.scrollXMax, + opacity : 0.5 + }, + 'duration' : opt_time, + 'easing' : opt_easing, + 'lazyRelease' : opt_release + }); }; that.scrollX = x; @@ -352,8 +407,8 @@ function X_UI_ScrollBox_onStart( e ){ //console.log( '-1-' ); this[ 'dispatch' ]( XUI_Event.SCROLL_END ); // TODO current位置 - this.xnodeSlider[ 'stop' ](); - }; + XUI_ScrollBox_useCSSP ? this.xnodeSlider[ 'stop' ]() : this.xnode[ 'stop' ](); + }; this.startX = this.scrollX; this.startY = this.scrollY; @@ -381,7 +436,7 @@ function X_UI_ScrollBox_onMove( e ){ }; // gpu の用意 - if( !this.xnodeSlider[ '_anime' ] ){ + if( !XUI_ScrollBox_useCSSP ? ( !this.xnode[ '_anime' ] || !this.xnode[ '_anime' ].phase ) : ( !this.xnodeSlider[ '_anime' ] || !this.xnodeSlider[ '_anime' ].phase ) ){ //console.log( 'gpuレイヤーの用意 ' + e.pageY ); //console.log( 'mov1 x:' + this.scrollX + ' y:' + this.scrollY ); X_UI_ScrollBox_translate( this, this.scrollX, this.scrollY, 0, '', 300 ); @@ -454,7 +509,7 @@ function X_UI_ScrollBox_onMove( e ){ this.directionX = 0 < deltaX ? -1 : deltaX < 0 ? 1 : 0; this.directionY = 0 < deltaY ? -1 : deltaY < 0 ? 1 : 0; - //console.log( 'mov2 x:' + newX + ' y:' + newY ); + console.log( 'mov2 x:' + newX + ' y:' + newY ); X_UI_ScrollBox_translate( this, newX, newY, 0, '', 300 ); if( 300 < timestamp - this.startTime ){ @@ -571,11 +626,7 @@ function X_UI_ScrollBox_resetPosition( that, time ){ }; function X_UI_ScrollBox_onAnimeEnd( e ){ - if( e.target !== this.xnodeSlider ){ - console.log( '- not much -' ); - console.dir(e); - }; - if( e.target === this.xnodeSlider && this.isInTransition && !X_UI_ScrollBox_resetPosition( this, this.bounceTime ) ){ + if( this.isInTransition && !X_UI_ScrollBox_resetPosition( this, this.bounceTime ) ){ this.isInTransition = false; //console.log( '-2-' ); this[ 'dispatch' ]( XUI_Event.SCROLL_END );