Last active
May 12, 2016 23:19
-
-
Save s-hiroshi/97f0173afa51305741b2 to your computer and use it in GitHub Desktop.
JavaScriptで画面リサイズ(resize)を監視するサンプルです。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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