Diff
checker
文本
文本
图像
文档
Excel
文件夹
Legal
Enterprise
桌面版
定价
登录
下载 Diffchecker 桌面版
比较文本
查找两个文本文件之间的差异
工具
历史
实时编辑器
折叠未更改行
关闭换行
视图
拆分
统一
比对精度
智能
单词
字符
语法高亮
选择语法
忽略
文本转换
转到第一个差异
编辑输入
Diffchecker Desktop
运行Diffchecker最安全的方式。获取Diffchecker桌面应用:您的差异永远不会离开您的电脑!
获取桌面版
Untitled diff
创建于
8年前
差异永不过期
清除
导出
分享
解释
4 删除
行
总计
删除
字符
总计
删除
要继续使用此功能,请升级到
Diff
checker
Pro
查看价格
456 行
全部复制
3 添加
行
总计
添加
字符
总计
添加
要继续使用此功能,请升级到
Diff
checker
Pro
查看价格
455 行
全部复制
// ----------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------
// ScrollMe
// ScrollMe
// A jQuery plugin for adding simple scrolling effects to web pages
// A jQuery plugin for adding simple scrolling effects to web pages
// http://scrollme.nckprsn.com
// http://scrollme.nckprsn.com
// ----------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------
var scrollme = ( function( $ )
var scrollme = ( function( $ )
{
{
// ----------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------
// ScrollMe object
// ScrollMe object
var _this = {};
var _this = {};
// ----------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------
// Properties
// Properties
var $document = $( document );
var $document = $( document );
var $window = $( window );
var $window = $( window );
_this.body_height = 0;
_this.body_height = 0;
_this.viewport_height = 0;
_this.viewport_height = 0;
_this.viewport_top = 0;
_this.viewport_top = 0;
_this.viewport_bottom = 0;
_this.viewport_bottom = 0;
_this.viewport_top_previous = -1;
_this.viewport_top_previous = -1;
_this.elements = [];
_this.elements = [];
_this.elements_in_view = [];
_this.elements_in_view = [];
_this.property_defaults =
_this.property_defaults =
{
{
'opacity' : 1,
'opacity' : 1,
'translatex' : 0,
'translatex' : 0,
'translatey' : 0,
'translatey' : 0,
'translatez' : 0,
'translatez' : 0,
'rotatex' : 0,
'rotatex' : 0,
'rotatey' : 0,
'rotatey' : 0,
'rotatez' : 0,
'rotatez' : 0,
'scale' : 1,
'scale' : 1,
'scalex' : 1,
'scalex' : 1,
'scaley' : 1,
'scaley' : 1,
'scalez' : 1
'scalez' : 1
};
};
_this.scrollme_selector = '.scrollme';
_this.scrollme_selector = '.scrollme';
_this.animateme_selector = '.animateme';
_this.animateme_selector = '.animateme';
_this.update_interval = 10;
_this.update_interval = 10;
// Easing functions
// Easing functions
_this.easing_functions =
_this.easing_functions =
{
{
'linear' : function( x )
'linear' : function( x )
{
{
return x;
return x;
},
},
'easeout' : function( x )
'easeout' : function( x )
{
{
return x * x * x;
return x * x * x;
},
},
'easein' : function( x )
'easein' : function( x )
{
{
x = 1 - x;
x = 1 - x;
return 1 - ( x * x * x );
return 1 - ( x * x * x );
},
},
'easeinout' : function( x )
'easeinout' : function( x )
{
{
if( x < 0.5 )
if( x < 0.5 )
{
{
return ( 4 * x * x * x );
return ( 4 * x * x * x );
}
}
else
else
{
{
x = 1 - x;
x = 1 - x;
return 1 - ( 4 * x * x * x ) ;
return 1 - ( 4 * x * x * x ) ;
}
}
}
}
};
};
// Document events to bind initialisation to
// Document events to bind initialisation to
_this.init_events =
_this.init_events =
[
[
'ready',
'ready',
'page:load', // Turbolinks
'page:load', // Turbolinks
'page:change' // Turbolinks
'page:change' // Turbolinks
];
];
// ----------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------
// Initialisation conditions
// Initialisation conditions
_this.init_if = function() { return true; }
_this.init_if = function() { return true; }
// ----------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------
// Initialisation
// Initialisation
_this.init = function()
_this.init = function()
{
{
// Cancel if initialisation conditions not met
// Cancel if initialisation conditions not met
if( !_this.init_if() ) return false;
if( !_this.init_if() ) return false;
// Load all elements to animate
// Load all elements to animate
_this.init_elements();
_this.init_elements();
// Get element & viewport sizes
// Get element & viewport sizes
_this.on_resize();
_this.on_resize();
// Recalculate heights & positions on resize and rotate
// Recalculate heights & positions on resize and rotate
$window.on( 'resize orientationchange' , function(){ _this.on_resize(); } );
$window.on( 'resize orientationchange' , function(){ _this.on_resize(); } );
// Recalculate heights & positions when page is fully loaded + a bit just in case
// Recalculate heights & positions when page is fully loaded + a bit just in case
复制
已复制
复制
已复制
$
(document).ready
( function(){ setTimeout( function(){ _this.on_resize(); } , 100 ) });
$
window.load
( function(){ setTimeout( function(){ _this.on_resize(); } , 100 ) });
// Start animating
// Start animating
setInterval( _this.update , _this.update_interval );
setInterval( _this.update , _this.update_interval );
return true;
return true;
}
}
// ----------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------
// Get list and pre-load animated elements
// Get list and pre-load animated elements
_this.init_elements = function()
_this.init_elements = function()
{
{
// For each reference element
// For each reference element
$( _this.scrollme_selector ).each( function()
$( _this.scrollme_selector ).each( function()
{
{
var element = {};
var element = {};
element.element = $( this );
element.element = $( this );
var effects = [];
var effects = [];
// For each animated element
// For each animated element
$( this ).find( _this.animateme_selector ).addBack( _this.animateme_selector ).each( function()
$( this ).find( _this.animateme_selector ).addBack( _this.animateme_selector ).each( function()
{
{
// Get effect details
// Get effect details
var effect = {};
var effect = {};
effect.element = $( this );
effect.element = $( this );
effect.when = effect.element.data( 'when' );
effect.when = effect.element.data( 'when' );
effect.from = effect.element.data( 'from' );
effect.from = effect.element.data( 'from' );
effect.to = effect.element.data( 'to' );
effect.to = effect.element.data( 'to' );
if( effect.element.is( '[data-crop]' ) )
if( effect.element.is( '[data-crop]' ) )
{
{
effect.crop = effect.element.data( 'crop' );
effect.crop = effect.element.data( 'crop' );
}
}
else
else
{
{
effect.crop = true;
effect.crop = true;
}
}
if( effect.element.is( '[data-easing]' ) )
if( effect.element.is( '[data-easing]' ) )
{
{
effect.easing = _this.easing_functions[ effect.element.data( 'easing' ) ]
effect.easing = _this.easing_functions[ effect.element.data( 'easing' ) ]
}
}
else
else
{
{
effect.easing = _this.easing_functions[ 'easeout' ];
effect.easing = _this.easing_functions[ 'easeout' ];
}
}
// Get animated properties
// Get animated properties
var properties = {};
var properties = {};
if( effect.element.is( '[data-opacity]' ) ) properties.opacity = effect.element.data( 'opacity' );
if( effect.element.is( '[data-opacity]' ) ) properties.opacity = effect.element.data( 'opacity' );
if( effect.element.is( '[data-translatex]' ) ) properties.translatex = effect.element.data( 'translatex' );
if( effect.element.is( '[data-translatex]' ) ) properties.translatex = effect.element.data( 'translatex' );
if( effect.element.is( '[data-translatey]' ) ) properties.translatey = effect.element.data( 'translatey' );
if( effect.element.is( '[data-translatey]' ) ) properties.translatey = effect.element.data( 'translatey' );
if( effect.element.is( '[data-translatez]' ) ) properties.translatez = effect.element.data( 'translatez' );
if( effect.element.is( '[data-translatez]' ) ) properties.translatez = effect.element.data( 'translatez' );
if( effect.element.is( '[data-rotatex]' ) ) properties.rotatex = effect.element.data( 'rotatex' );
if( effect.element.is( '[data-rotatex]' ) ) properties.rotatex = effect.element.data( 'rotatex' );
if( effect.element.is( '[data-rotatey]' ) ) properties.rotatey = effect.element.data( 'rotatey' );
if( effect.element.is( '[data-rotatey]' ) ) properties.rotatey = effect.element.data( 'rotatey' );
if( effect.element.is( '[data-rotatez]' ) ) properties.rotatez = effect.element.data( 'rotatez' );
if( effect.element.is( '[data-rotatez]' ) ) properties.rotatez = effect.element.data( 'rotatez' );
if( effect.element.is( '[data-scale]' ) ) properties.scale = effect.element.data( 'scale' );
if( effect.element.is( '[data-scale]' ) ) properties.scale = effect.element.data( 'scale' );
if( effect.element.is( '[data-scalex]' ) ) properties.scalex = effect.element.data( 'scalex' );
if( effect.element.is( '[data-scalex]' ) ) properties.scalex = effect.element.data( 'scalex' );
if( effect.element.is( '[data-scaley]' ) ) properties.scaley = effect.element.data( 'scaley' );
if( effect.element.is( '[data-scaley]' ) ) properties.scaley = effect.element.data( 'scaley' );
if( effect.element.is( '[data-scalez]' ) ) properties.scalez = effect.element.data( 'scalez' );
if( effect.element.is( '[data-scalez]' ) ) properties.scalez = effect.element.data( 'scalez' );
effect.properties = properties;
effect.properties = properties;
effects.push( effect );
effects.push( effect );
});
});
element.effects = effects;
element.effects = effects;
_this.elements.push( element );
_this.elements.push( element );
});
});
}
}
// ----------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------
// Update elements
// Update elements
_this.update = function()
_this.update = function()
{
{
window.requestAnimationFrame( function()
window.requestAnimationFrame( function()
{
{
_this.update_viewport_position();
_this.update_viewport_position();
if( _this.viewport_top_previous != _this.viewport_top )
if( _this.viewport_top_previous != _this.viewport_top )
{
{
_this.update_elements_in_view();
_this.update_elements_in_view();
_this.animate();
_this.animate();
}
}
_this.viewport_top_previous = _this.viewport_top;
_this.viewport_top_previous = _this.viewport_top;
});
});
}
}
// ----------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------
// Animate stuff
// Animate stuff
_this.animate = function()
_this.animate = function()
{
{
// For each element in viewport
// For each element in viewport
var elements_in_view_length = _this.elements_in_view.length;
var elements_in_view_length = _this.elements_in_view.length;
for( var i=0 ; i<elements_in_view_length ; i++ )
for( var i=0 ; i<elements_in_view_length ; i++ )
{
{
var element = _this.elements_in_view[i];
var element = _this.elements_in_view[i];
// For each effect
// For each effect
var effects_length = element.effects.length;
var effects_length = element.effects.length;
for( var e=0 ; e<effects_length ; e++ )
for( var e=0 ; e<effects_length ; e++ )
{
{
var effect = element.effects[e];
var effect = element.effects[e];
// Get effect animation boundaries
// Get effect animation boundaries
switch( effect.when )
switch( effect.when )
{
{
case 'view' : // Maintained for backwards compatibility
case 'view' : // Maintained for backwards compatibility
case 'span' :
case 'span' :
var start = element.top - _this.viewport_height;
var start = element.top - _this.viewport_height;
var end = element.bottom;
var end = element.bottom;
break;
break;
case 'exit' :
case 'exit' :
var start = element.bottom - _this.viewport_height;
var start = element.bottom - _this.viewport_height;
var end = element.bottom;
var end = element.bottom;
break;
break;
default :
default :
var start = element.top - _this.viewport_height;
var start = element.top - _this.viewport_height;
var end = element.top;
var end = element.top;
break;
break;
}
}
// Crop boundaries
// Crop boundaries
if( effect.crop )
if( effect.crop )
{
{
if( start < 0 ) start = 0;
if( start < 0 ) start = 0;
if( end > ( _this.body_height - _this.viewport_height ) ) end = _this.body_height - _this.viewport_height;
if( end > ( _this.body_height - _this.viewport_height ) ) end = _this.body_height - _this.viewport_height;
}
}
// Get scroll position of reference selector
// Get scroll position of reference selector
var scroll = ( _this.viewport_top - start ) / ( end - start );
var scroll = ( _this.viewport_top - start ) / ( end - start );
// Get relative scroll position for effect
// Get relative scroll position for effect
var from = effect[ 'from' ];
var from = effect[ 'from' ];
var to = effect[ 'to' ];
var to = effect[ 'to' ];
var length = to - from;
var length = to - from;
var scroll_relative = ( scroll - from ) / length;
var scroll_relative = ( scroll - from ) / length;
// Apply easing
// Apply easing
var scroll_eased = effect.easing( scroll_relative );
var scroll_eased = effect.easing( scroll_relative );
// Get new value for each property
// Get new value for each property
var opacity = _this.animate_value( scroll , scroll_eased , from , to , effect , 'opacity' );
var opacity = _this.animate_value( scroll , scroll_eased , from , to , effect , 'opacity' );
var translatey = _this.animate_value( scroll , scroll_eased , from , to , effect , 'translatey' );
var translatey = _this.animate_value( scroll , scroll_eased , from , to , effect , 'translatey' );
var translatex = _this.animate_value( scroll , scroll_eased , from , to , effect , 'translatex' );
var translatex = _this.animate_value( scroll , scroll_eased , from , to , effect , 'translatex' );
var translatez = _this.animate_value( scroll , scroll_eased , from , to , effect , 'translatez' );
var translatez = _this.animate_value( scroll , scroll_eased , from , to , effect , 'translatez' );
var rotatex = _this.animate_value( scroll , scroll_eased , from , to , effect , 'rotatex' );
var rotatex = _this.animate_value( scroll , scroll_eased , from , to , effect , 'rotatex' );
var rotatey = _this.animate_value( scroll , scroll_eased , from , to , effect , 'rotatey' );
var rotatey = _this.animate_value( scroll , scroll_eased , from , to , effect , 'rotatey' );
var rotatez = _this.animate_value( scroll , scroll_eased , from , to , effect , 'rotatez' );
var rotatez = _this.animate_value( scroll , scroll_eased , from , to , effect , 'rotatez' );
var scale = _this.animate_value( scroll , scroll_eased , from , to , effect , 'scale' );
var scale = _this.animate_value( scroll , scroll_eased , from , to , effect , 'scale' );
var scalex = _this.animate_value( scroll , scroll_eased , from , to , effect , 'scalex' );
var scalex = _this.animate_value( scroll , scroll_eased , from , to , effect , 'scalex' );
var scaley = _this.animate_value( scroll , scroll_eased , from , to , effect , 'scaley' );
var scaley = _this.animate_value( scroll , scroll_eased , from , to , effect , 'scaley' );
var scalez = _this.animate_value( scroll , scroll_eased , from , to , effect , 'scalez' );
var scalez = _this.animate_value( scroll , scroll_eased , from , to , effect , 'scalez' );
// Override scale values
// Override scale values
if( 'scale' in effect.properties )
if( 'scale' in effect.properties )
{
{
scalex = scale;
scalex = scale;
scaley = scale;
scaley = scale;
scalez = scale;
scalez = scale;
}
}
// Update properties
// Update properties
effect.element.css(
effect.element.css(
{
{
'opacity' : opacity,
'opacity' : opacity,
'transform' : 'translate3d( '+translatex+'px , '+translatey+'px , '+translatez+'px ) rotateX( '+rotatex+'deg ) rotateY( '+rotatey+'deg ) rotateZ( '+rotatez+'deg ) scale3d( '+scalex+' , '+scaley+' , '+scalez+' )'
'transform' : 'translate3d( '+translatex+'px , '+translatey+'px , '+translatez+'px ) rotateX( '+rotatex+'deg ) rotateY( '+rotatey+'deg ) rotateZ( '+rotatez+'deg ) scale3d( '+scalex+' , '+scaley+' , '+scalez+' )'
} );
} );
}
}
}
}
}
}
// ----------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------
// Calculate property values
// Calculate property values
_this.animate_value = function( scroll , scroll_eased , from , to , effect , property )
_this.animate_value = function( scroll , scroll_eased , from , to , effect , property )
{
{
var value_default = _this.property_defaults[ property ];
var value_default = _this.property_defaults[ property ];
// Return default value if property is not animated
// Return default value if property is not animated
if( !( property in effect.properties ) ) return value_default;
if( !( property in effect.properties ) ) return value_default;
var value_target = effect.properties[ property ];
var value_target = effect.properties[ property ];
var forwards = ( to > from ) ? true : false;
var forwards = ( to > from ) ? true : false;
// Return boundary value if outside effect boundaries
// Return boundary value if outside effect boundaries
if( scroll < from && forwards ) { return value_default; }
if( scroll < from && forwards ) { return value_default; }
if( scroll > to && forwards ) { return value_target; }
if( scroll > to && forwards ) { return value_target; }
if( scroll > from && !forwards ) { return value_default; }
if( scroll > from && !forwards ) { return value_default; }
if( scroll < to && !forwards ) { return value_target; }
if( scroll < to && !forwards ) { return value_target; }
// Calculate new property value
// Calculate new property value
var new_value = value_default + ( scroll_eased * ( value_target - value_default ) );
var new_value = value_default + ( scroll_eased * ( value_target - value_default ) );
// Round as required
// Round as required
switch( property )
switch( property )
{
{
case 'opacity' : new_value = new_value.toFixed(2); break;
case 'opacity' : new_value = new_value.toFixed(2); break;
case 'translatex' : new_value = new_value.toFixed(0); break;
case 'translatex' : new_value = new_value.toFixed(0); break;
case 'translatey' : new_value = new_value.toFixed(0); break;
case 'translatey' : new_value = new_value.toFixed(0); break;
case 'translatez' : new_value = new_value.toFixed(0); break;
case 'translatez' : new_value = new_value.toFixed(0); break;
case 'rotatex' : new_value = new_value.toFixed(1); break;
case 'rotatex' : new_value = new_value.toFixed(1); break;
case 'rotatey' : new_value = new_value.toFixed(1); break;
case 'rotatey' : new_value = new_value.toFixed(1); break;
case 'rotatez' : new_value = new_value.toFixed(1); break;
case 'rotatez' : new_value = new_value.toFixed(1); break;
case 'scale' : new_value = new_value.toFixed(3); break;
case 'scale' : new_value = new_value.toFixed(3); break;
default : break;
default : break;
}
}
// Done
// Done
return new_value;
return new_value;
}
}
// ----------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------
// Update viewport position
// Update viewport position
_this.update_viewport_position = function()
_this.update_viewport_position = function()
{
{
_this.viewport_top = $window.scrollTop();
_this.viewport_top = $window.scrollTop();
_this.viewport_bottom = _this.viewport_top + _this.viewport_height;
_this.viewport_bottom = _this.viewport_top + _this.viewport_height;
}
}
// ----------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------
// Update list of elements in view
// Update list of elements in view
_this.update_elements_in_view = function()
_this.update_elements_in_view = function()
{
{
_this.elements_in_view = [];
_this.elements_in_view = [];
var elements_length = _this.elements.length;
var elements_length = _this.elements.length;
for( var i=0 ; i<elements_length ; i++ )
for( var i=0 ; i<elements_length ; i++ )
{
{
if ( ( _this.elements[i].top < _this.viewport_bottom ) && ( _this.elements[i].bottom > _this.viewport_top ) )
if ( ( _this.elements[i].top < _this.viewport_bottom ) && ( _this.elements[i].bottom > _this.viewport_top ) )
{
{
_this.elements_in_view.push( _this.elements[i] );
_this.elements_in_view.push( _this.elements[i] );
}
}
}
}
}
}
// ----------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------
// Stuff to do on resize
// Stuff to do on resize
_this.on_resize = function()
_this.on_resize = function()
{
{
// Update viewport/element data
// Update viewport/element data
_this.update_viewport();
_this.update_viewport();
_this.update_element_heights();
_this.update_element_heights();
// Update display
// Update display
_this.update_viewport_position();
_this.update_viewport_position();
_this.update_elements_in_view();
_this.update_elements_in_view();
_this.animate();
_this.animate();
}
}
// ----------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------
// Update viewport parameters
// Update viewport parameters
_this.update_viewport = function()
_this.update_viewport = function()
{
{
_this.body_height = $document.height();
_this.body_height = $document.height();
_this.viewport_height = $window.height();
_this.viewport_height = $window.height();
}
}
// ----------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------
// Update height of animated elements
// Update height of animated elements
_this.update_element_heights = function()
_this.update_element_heights = function()
{
{
var elements_length = _this.elements.length;
var elements_length = _this.elements.length;
for( var i=0 ; i<elements_length ; i++ )
for( var i=0 ; i<elements_length ; i++ )
{
{
var element_height = _this.elements[i].element.outerHeight();
var element_height = _this.elements[i].element.outerHeight();
var position = _this.elements[i].element.offset();
var position = _this.elements[i].element.offset();
_this.elements[i].height = element_height;
_this.elements[i].height = element_height;
_this.elements[i].top = position.top;
_this.elements[i].top = position.top;
_this.elements[i].bottom = position.top + element_height;
_this.elements[i].bottom = position.top + element_height;
}
}
}
}
// ----------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------
// Bind initialisation
// Bind initialisation
复制
已复制
复制
已复制
$
('
document
').ready(
function(){ _this.init(); }
);
$
document
.on( _this.init_events.join( ' ' ) ,
function(){ _this.init(); }
);
// ----------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------
return _this;
return _this;
// ----------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------
})( jQuery );
})( jQuery );
复制
已复制
复制
已复制
已保存差异
原始文本
打开文件
// ---------------------------------------------------------------------------------------------------- // ScrollMe // A jQuery plugin for adding simple scrolling effects to web pages // http://scrollme.nckprsn.com // ---------------------------------------------------------------------------------------------------- var scrollme = ( function( $ ) { // ---------------------------------------------------------------------------------------------------- // ScrollMe object var _this = {}; // ---------------------------------------------------------------------------------------------------- // Properties var $document = $( document ); var $window = $( window ); _this.body_height = 0; _this.viewport_height = 0; _this.viewport_top = 0; _this.viewport_bottom = 0; _this.viewport_top_previous = -1; _this.elements = []; _this.elements_in_view = []; _this.property_defaults = { 'opacity' : 1, 'translatex' : 0, 'translatey' : 0, 'translatez' : 0, 'rotatex' : 0, 'rotatey' : 0, 'rotatez' : 0, 'scale' : 1, 'scalex' : 1, 'scaley' : 1, 'scalez' : 1 }; _this.scrollme_selector = '.scrollme'; _this.animateme_selector = '.animateme'; _this.update_interval = 10; // Easing functions _this.easing_functions = { 'linear' : function( x ) { return x; }, 'easeout' : function( x ) { return x * x * x; }, 'easein' : function( x ) { x = 1 - x; return 1 - ( x * x * x ); }, 'easeinout' : function( x ) { if( x < 0.5 ) { return ( 4 * x * x * x ); } else { x = 1 - x; return 1 - ( 4 * x * x * x ) ; } } }; // Document events to bind initialisation to _this.init_events = [ 'ready', 'page:load', // Turbolinks 'page:change' // Turbolinks ]; // ---------------------------------------------------------------------------------------------------- // Initialisation conditions _this.init_if = function() { return true; } // ---------------------------------------------------------------------------------------------------- // Initialisation _this.init = function() { // Cancel if initialisation conditions not met if( !_this.init_if() ) return false; // Load all elements to animate _this.init_elements(); // Get element & viewport sizes _this.on_resize(); // Recalculate heights & positions on resize and rotate $window.on( 'resize orientationchange' , function(){ _this.on_resize(); } ); // Recalculate heights & positions when page is fully loaded + a bit just in case $(document).ready( function(){ setTimeout( function(){ _this.on_resize(); } , 100 ) }); // Start animating setInterval( _this.update , _this.update_interval ); return true; } // ---------------------------------------------------------------------------------------------------- // Get list and pre-load animated elements _this.init_elements = function() { // For each reference element $( _this.scrollme_selector ).each( function() { var element = {}; element.element = $( this ); var effects = []; // For each animated element $( this ).find( _this.animateme_selector ).addBack( _this.animateme_selector ).each( function() { // Get effect details var effect = {}; effect.element = $( this ); effect.when = effect.element.data( 'when' ); effect.from = effect.element.data( 'from' ); effect.to = effect.element.data( 'to' ); if( effect.element.is( '[data-crop]' ) ) { effect.crop = effect.element.data( 'crop' ); } else { effect.crop = true; } if( effect.element.is( '[data-easing]' ) ) { effect.easing = _this.easing_functions[ effect.element.data( 'easing' ) ] } else { effect.easing = _this.easing_functions[ 'easeout' ]; } // Get animated properties var properties = {}; if( effect.element.is( '[data-opacity]' ) ) properties.opacity = effect.element.data( 'opacity' ); if( effect.element.is( '[data-translatex]' ) ) properties.translatex = effect.element.data( 'translatex' ); if( effect.element.is( '[data-translatey]' ) ) properties.translatey = effect.element.data( 'translatey' ); if( effect.element.is( '[data-translatez]' ) ) properties.translatez = effect.element.data( 'translatez' ); if( effect.element.is( '[data-rotatex]' ) ) properties.rotatex = effect.element.data( 'rotatex' ); if( effect.element.is( '[data-rotatey]' ) ) properties.rotatey = effect.element.data( 'rotatey' ); if( effect.element.is( '[data-rotatez]' ) ) properties.rotatez = effect.element.data( 'rotatez' ); if( effect.element.is( '[data-scale]' ) ) properties.scale = effect.element.data( 'scale' ); if( effect.element.is( '[data-scalex]' ) ) properties.scalex = effect.element.data( 'scalex' ); if( effect.element.is( '[data-scaley]' ) ) properties.scaley = effect.element.data( 'scaley' ); if( effect.element.is( '[data-scalez]' ) ) properties.scalez = effect.element.data( 'scalez' ); effect.properties = properties; effects.push( effect ); }); element.effects = effects; _this.elements.push( element ); }); } // ---------------------------------------------------------------------------------------------------- // Update elements _this.update = function() { window.requestAnimationFrame( function() { _this.update_viewport_position(); if( _this.viewport_top_previous != _this.viewport_top ) { _this.update_elements_in_view(); _this.animate(); } _this.viewport_top_previous = _this.viewport_top; }); } // ---------------------------------------------------------------------------------------------------- // Animate stuff _this.animate = function() { // For each element in viewport var elements_in_view_length = _this.elements_in_view.length; for( var i=0 ; i<elements_in_view_length ; i++ ) { var element = _this.elements_in_view[i]; // For each effect var effects_length = element.effects.length; for( var e=0 ; e<effects_length ; e++ ) { var effect = element.effects[e]; // Get effect animation boundaries switch( effect.when ) { case 'view' : // Maintained for backwards compatibility case 'span' : var start = element.top - _this.viewport_height; var end = element.bottom; break; case 'exit' : var start = element.bottom - _this.viewport_height; var end = element.bottom; break; default : var start = element.top - _this.viewport_height; var end = element.top; break; } // Crop boundaries if( effect.crop ) { if( start < 0 ) start = 0; if( end > ( _this.body_height - _this.viewport_height ) ) end = _this.body_height - _this.viewport_height; } // Get scroll position of reference selector var scroll = ( _this.viewport_top - start ) / ( end - start ); // Get relative scroll position for effect var from = effect[ 'from' ]; var to = effect[ 'to' ]; var length = to - from; var scroll_relative = ( scroll - from ) / length; // Apply easing var scroll_eased = effect.easing( scroll_relative ); // Get new value for each property var opacity = _this.animate_value( scroll , scroll_eased , from , to , effect , 'opacity' ); var translatey = _this.animate_value( scroll , scroll_eased , from , to , effect , 'translatey' ); var translatex = _this.animate_value( scroll , scroll_eased , from , to , effect , 'translatex' ); var translatez = _this.animate_value( scroll , scroll_eased , from , to , effect , 'translatez' ); var rotatex = _this.animate_value( scroll , scroll_eased , from , to , effect , 'rotatex' ); var rotatey = _this.animate_value( scroll , scroll_eased , from , to , effect , 'rotatey' ); var rotatez = _this.animate_value( scroll , scroll_eased , from , to , effect , 'rotatez' ); var scale = _this.animate_value( scroll , scroll_eased , from , to , effect , 'scale' ); var scalex = _this.animate_value( scroll , scroll_eased , from , to , effect , 'scalex' ); var scaley = _this.animate_value( scroll , scroll_eased , from , to , effect , 'scaley' ); var scalez = _this.animate_value( scroll , scroll_eased , from , to , effect , 'scalez' ); // Override scale values if( 'scale' in effect.properties ) { scalex = scale; scaley = scale; scalez = scale; } // Update properties effect.element.css( { 'opacity' : opacity, 'transform' : 'translate3d( '+translatex+'px , '+translatey+'px , '+translatez+'px ) rotateX( '+rotatex+'deg ) rotateY( '+rotatey+'deg ) rotateZ( '+rotatez+'deg ) scale3d( '+scalex+' , '+scaley+' , '+scalez+' )' } ); } } } // ---------------------------------------------------------------------------------------------------- // Calculate property values _this.animate_value = function( scroll , scroll_eased , from , to , effect , property ) { var value_default = _this.property_defaults[ property ]; // Return default value if property is not animated if( !( property in effect.properties ) ) return value_default; var value_target = effect.properties[ property ]; var forwards = ( to > from ) ? true : false; // Return boundary value if outside effect boundaries if( scroll < from && forwards ) { return value_default; } if( scroll > to && forwards ) { return value_target; } if( scroll > from && !forwards ) { return value_default; } if( scroll < to && !forwards ) { return value_target; } // Calculate new property value var new_value = value_default + ( scroll_eased * ( value_target - value_default ) ); // Round as required switch( property ) { case 'opacity' : new_value = new_value.toFixed(2); break; case 'translatex' : new_value = new_value.toFixed(0); break; case 'translatey' : new_value = new_value.toFixed(0); break; case 'translatez' : new_value = new_value.toFixed(0); break; case 'rotatex' : new_value = new_value.toFixed(1); break; case 'rotatey' : new_value = new_value.toFixed(1); break; case 'rotatez' : new_value = new_value.toFixed(1); break; case 'scale' : new_value = new_value.toFixed(3); break; default : break; } // Done return new_value; } // ---------------------------------------------------------------------------------------------------- // Update viewport position _this.update_viewport_position = function() { _this.viewport_top = $window.scrollTop(); _this.viewport_bottom = _this.viewport_top + _this.viewport_height; } // ---------------------------------------------------------------------------------------------------- // Update list of elements in view _this.update_elements_in_view = function() { _this.elements_in_view = []; var elements_length = _this.elements.length; for( var i=0 ; i<elements_length ; i++ ) { if ( ( _this.elements[i].top < _this.viewport_bottom ) && ( _this.elements[i].bottom > _this.viewport_top ) ) { _this.elements_in_view.push( _this.elements[i] ); } } } // ---------------------------------------------------------------------------------------------------- // Stuff to do on resize _this.on_resize = function() { // Update viewport/element data _this.update_viewport(); _this.update_element_heights(); // Update display _this.update_viewport_position(); _this.update_elements_in_view(); _this.animate(); } // ---------------------------------------------------------------------------------------------------- // Update viewport parameters _this.update_viewport = function() { _this.body_height = $document.height(); _this.viewport_height = $window.height(); } // ---------------------------------------------------------------------------------------------------- // Update height of animated elements _this.update_element_heights = function() { var elements_length = _this.elements.length; for( var i=0 ; i<elements_length ; i++ ) { var element_height = _this.elements[i].element.outerHeight(); var position = _this.elements[i].element.offset(); _this.elements[i].height = element_height; _this.elements[i].top = position.top; _this.elements[i].bottom = position.top + element_height; } } // ---------------------------------------------------------------------------------------------------- // Bind initialisation $('document').ready(function(){ _this.init(); }); // ---------------------------------------------------------------------------------------------------- return _this; // ---------------------------------------------------------------------------------------------------- })( jQuery );
更改后文本
打开文件
// ---------------------------------------------------------------------------------------------------- // ScrollMe // A jQuery plugin for adding simple scrolling effects to web pages // http://scrollme.nckprsn.com // ---------------------------------------------------------------------------------------------------- var scrollme = ( function( $ ) { // ---------------------------------------------------------------------------------------------------- // ScrollMe object var _this = {}; // ---------------------------------------------------------------------------------------------------- // Properties var $document = $( document ); var $window = $( window ); _this.body_height = 0; _this.viewport_height = 0; _this.viewport_top = 0; _this.viewport_bottom = 0; _this.viewport_top_previous = -1; _this.elements = []; _this.elements_in_view = []; _this.property_defaults = { 'opacity' : 1, 'translatex' : 0, 'translatey' : 0, 'translatez' : 0, 'rotatex' : 0, 'rotatey' : 0, 'rotatez' : 0, 'scale' : 1, 'scalex' : 1, 'scaley' : 1, 'scalez' : 1 }; _this.scrollme_selector = '.scrollme'; _this.animateme_selector = '.animateme'; _this.update_interval = 10; // Easing functions _this.easing_functions = { 'linear' : function( x ) { return x; }, 'easeout' : function( x ) { return x * x * x; }, 'easein' : function( x ) { x = 1 - x; return 1 - ( x * x * x ); }, 'easeinout' : function( x ) { if( x < 0.5 ) { return ( 4 * x * x * x ); } else { x = 1 - x; return 1 - ( 4 * x * x * x ) ; } } }; // Document events to bind initialisation to _this.init_events = [ 'ready', 'page:load', // Turbolinks 'page:change' // Turbolinks ]; // ---------------------------------------------------------------------------------------------------- // Initialisation conditions _this.init_if = function() { return true; } // ---------------------------------------------------------------------------------------------------- // Initialisation _this.init = function() { // Cancel if initialisation conditions not met if( !_this.init_if() ) return false; // Load all elements to animate _this.init_elements(); // Get element & viewport sizes _this.on_resize(); // Recalculate heights & positions on resize and rotate $window.on( 'resize orientationchange' , function(){ _this.on_resize(); } ); // Recalculate heights & positions when page is fully loaded + a bit just in case $window.load( function(){ setTimeout( function(){ _this.on_resize(); } , 100 ) }); // Start animating setInterval( _this.update , _this.update_interval ); return true; } // ---------------------------------------------------------------------------------------------------- // Get list and pre-load animated elements _this.init_elements = function() { // For each reference element $( _this.scrollme_selector ).each( function() { var element = {}; element.element = $( this ); var effects = []; // For each animated element $( this ).find( _this.animateme_selector ).addBack( _this.animateme_selector ).each( function() { // Get effect details var effect = {}; effect.element = $( this ); effect.when = effect.element.data( 'when' ); effect.from = effect.element.data( 'from' ); effect.to = effect.element.data( 'to' ); if( effect.element.is( '[data-crop]' ) ) { effect.crop = effect.element.data( 'crop' ); } else { effect.crop = true; } if( effect.element.is( '[data-easing]' ) ) { effect.easing = _this.easing_functions[ effect.element.data( 'easing' ) ] } else { effect.easing = _this.easing_functions[ 'easeout' ]; } // Get animated properties var properties = {}; if( effect.element.is( '[data-opacity]' ) ) properties.opacity = effect.element.data( 'opacity' ); if( effect.element.is( '[data-translatex]' ) ) properties.translatex = effect.element.data( 'translatex' ); if( effect.element.is( '[data-translatey]' ) ) properties.translatey = effect.element.data( 'translatey' ); if( effect.element.is( '[data-translatez]' ) ) properties.translatez = effect.element.data( 'translatez' ); if( effect.element.is( '[data-rotatex]' ) ) properties.rotatex = effect.element.data( 'rotatex' ); if( effect.element.is( '[data-rotatey]' ) ) properties.rotatey = effect.element.data( 'rotatey' ); if( effect.element.is( '[data-rotatez]' ) ) properties.rotatez = effect.element.data( 'rotatez' ); if( effect.element.is( '[data-scale]' ) ) properties.scale = effect.element.data( 'scale' ); if( effect.element.is( '[data-scalex]' ) ) properties.scalex = effect.element.data( 'scalex' ); if( effect.element.is( '[data-scaley]' ) ) properties.scaley = effect.element.data( 'scaley' ); if( effect.element.is( '[data-scalez]' ) ) properties.scalez = effect.element.data( 'scalez' ); effect.properties = properties; effects.push( effect ); }); element.effects = effects; _this.elements.push( element ); }); } // ---------------------------------------------------------------------------------------------------- // Update elements _this.update = function() { window.requestAnimationFrame( function() { _this.update_viewport_position(); if( _this.viewport_top_previous != _this.viewport_top ) { _this.update_elements_in_view(); _this.animate(); } _this.viewport_top_previous = _this.viewport_top; }); } // ---------------------------------------------------------------------------------------------------- // Animate stuff _this.animate = function() { // For each element in viewport var elements_in_view_length = _this.elements_in_view.length; for( var i=0 ; i<elements_in_view_length ; i++ ) { var element = _this.elements_in_view[i]; // For each effect var effects_length = element.effects.length; for( var e=0 ; e<effects_length ; e++ ) { var effect = element.effects[e]; // Get effect animation boundaries switch( effect.when ) { case 'view' : // Maintained for backwards compatibility case 'span' : var start = element.top - _this.viewport_height; var end = element.bottom; break; case 'exit' : var start = element.bottom - _this.viewport_height; var end = element.bottom; break; default : var start = element.top - _this.viewport_height; var end = element.top; break; } // Crop boundaries if( effect.crop ) { if( start < 0 ) start = 0; if( end > ( _this.body_height - _this.viewport_height ) ) end = _this.body_height - _this.viewport_height; } // Get scroll position of reference selector var scroll = ( _this.viewport_top - start ) / ( end - start ); // Get relative scroll position for effect var from = effect[ 'from' ]; var to = effect[ 'to' ]; var length = to - from; var scroll_relative = ( scroll - from ) / length; // Apply easing var scroll_eased = effect.easing( scroll_relative ); // Get new value for each property var opacity = _this.animate_value( scroll , scroll_eased , from , to , effect , 'opacity' ); var translatey = _this.animate_value( scroll , scroll_eased , from , to , effect , 'translatey' ); var translatex = _this.animate_value( scroll , scroll_eased , from , to , effect , 'translatex' ); var translatez = _this.animate_value( scroll , scroll_eased , from , to , effect , 'translatez' ); var rotatex = _this.animate_value( scroll , scroll_eased , from , to , effect , 'rotatex' ); var rotatey = _this.animate_value( scroll , scroll_eased , from , to , effect , 'rotatey' ); var rotatez = _this.animate_value( scroll , scroll_eased , from , to , effect , 'rotatez' ); var scale = _this.animate_value( scroll , scroll_eased , from , to , effect , 'scale' ); var scalex = _this.animate_value( scroll , scroll_eased , from , to , effect , 'scalex' ); var scaley = _this.animate_value( scroll , scroll_eased , from , to , effect , 'scaley' ); var scalez = _this.animate_value( scroll , scroll_eased , from , to , effect , 'scalez' ); // Override scale values if( 'scale' in effect.properties ) { scalex = scale; scaley = scale; scalez = scale; } // Update properties effect.element.css( { 'opacity' : opacity, 'transform' : 'translate3d( '+translatex+'px , '+translatey+'px , '+translatez+'px ) rotateX( '+rotatex+'deg ) rotateY( '+rotatey+'deg ) rotateZ( '+rotatez+'deg ) scale3d( '+scalex+' , '+scaley+' , '+scalez+' )' } ); } } } // ---------------------------------------------------------------------------------------------------- // Calculate property values _this.animate_value = function( scroll , scroll_eased , from , to , effect , property ) { var value_default = _this.property_defaults[ property ]; // Return default value if property is not animated if( !( property in effect.properties ) ) return value_default; var value_target = effect.properties[ property ]; var forwards = ( to > from ) ? true : false; // Return boundary value if outside effect boundaries if( scroll < from && forwards ) { return value_default; } if( scroll > to && forwards ) { return value_target; } if( scroll > from && !forwards ) { return value_default; } if( scroll < to && !forwards ) { return value_target; } // Calculate new property value var new_value = value_default + ( scroll_eased * ( value_target - value_default ) ); // Round as required switch( property ) { case 'opacity' : new_value = new_value.toFixed(2); break; case 'translatex' : new_value = new_value.toFixed(0); break; case 'translatey' : new_value = new_value.toFixed(0); break; case 'translatez' : new_value = new_value.toFixed(0); break; case 'rotatex' : new_value = new_value.toFixed(1); break; case 'rotatey' : new_value = new_value.toFixed(1); break; case 'rotatez' : new_value = new_value.toFixed(1); break; case 'scale' : new_value = new_value.toFixed(3); break; default : break; } // Done return new_value; } // ---------------------------------------------------------------------------------------------------- // Update viewport position _this.update_viewport_position = function() { _this.viewport_top = $window.scrollTop(); _this.viewport_bottom = _this.viewport_top + _this.viewport_height; } // ---------------------------------------------------------------------------------------------------- // Update list of elements in view _this.update_elements_in_view = function() { _this.elements_in_view = []; var elements_length = _this.elements.length; for( var i=0 ; i<elements_length ; i++ ) { if ( ( _this.elements[i].top < _this.viewport_bottom ) && ( _this.elements[i].bottom > _this.viewport_top ) ) { _this.elements_in_view.push( _this.elements[i] ); } } } // ---------------------------------------------------------------------------------------------------- // Stuff to do on resize _this.on_resize = function() { // Update viewport/element data _this.update_viewport(); _this.update_element_heights(); // Update display _this.update_viewport_position(); _this.update_elements_in_view(); _this.animate(); } // ---------------------------------------------------------------------------------------------------- // Update viewport parameters _this.update_viewport = function() { _this.body_height = $document.height(); _this.viewport_height = $window.height(); } // ---------------------------------------------------------------------------------------------------- // Update height of animated elements _this.update_element_heights = function() { var elements_length = _this.elements.length; for( var i=0 ; i<elements_length ; i++ ) { var element_height = _this.elements[i].element.outerHeight(); var position = _this.elements[i].element.offset(); _this.elements[i].height = element_height; _this.elements[i].top = position.top; _this.elements[i].bottom = position.top + element_height; } } // ---------------------------------------------------------------------------------------------------- // Bind initialisation $document.on( _this.init_events.join( ' ' ) , function(){ _this.init(); } ); // ---------------------------------------------------------------------------------------------------- return _this; // ---------------------------------------------------------------------------------------------------- })( jQuery );
查找差异