Skip to content

Instantly share code, notes, and snippets.

@s-hiroshi
Last active May 12, 2016 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s-hiroshi/97f0173afa51305741b2 to your computer and use it in GitHub Desktop.
Save s-hiroshi/97f0173afa51305741b2 to your computer and use it in GitHub Desktop.
JavaScriptで画面リサイズ(resize)を監視するサンプルです。
/**
* @module InfoTown
*/
jQuery( function ( $ ) {
/**
* Resizeオブジェクト
*
* スクロールを管理します。
*
* @class Resize
*/
InfoTown.Resize = (function () {
/**
* ウインドウの幅を監視してHTML要素の表示・非表示を管理
*
* @method display
* @public
* @param {jQuery} target 対象のjQueryオブジェクトです。
* @param {object} limit 閾値です。
*/
function display( target, limit ) {
target = (target instanceof jQuery) ? target : $( target );
$( window ).on( 'resize', function () {
if ( $( window ).width() > limit ) {
target.css( { "display": "block" } );
} else {
target.css( { "display": "none" } );
}
} );
}
/**
* ウィンドウリサイズでコールバック実行
*
* @method exec
* @public
* @param {Function} callback 実行するコールバック関数です。
*/
function exec( callback ) {
$( window ).on( 'resize', function () {
callback();
} )
}
/* パブリックメソッド */
return {
display: display,
exec: exec
};
})();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment