ウィンドウサイズによりプラグインを切り替えるjQueryのプラグインを作りました。
http://matometaru.com/switchingplugins/
ウィンドウリサイズ時にも適用したく以下のように追加してみました。
-
リサイズ関数内の options.switchingSize が undefined と出力されます。ウィンドウサイズを変えると480と出力されるときもあります。なぜでしょうか?
-
プラグインとして利用するために、改善すべき箇所はありますか?
以上の2点について、回答、アドバイスをよろしくお願いします。
lang
1;(function ($) { 2 $.fn.switchingPlugins = function (custom) { 3 4 //起動時のウィンドウサイズを取得 5 var width = window.innerWidth; 6 7 options = $.extend(true, { 8 switchingSize: 480, 9 //events 10 smallPlugin: function(){}, 11 bigPlugin: function(){}, 12 smallPluginDelete: function(){}, 13 bigPluginDelete: function(){} 14 }, custom); 15 16 /* ロード時に実行する */ 17 if(width <= options.switchingSize){ 18 options.smallPlugin(); 19 } 20 else{ 21 options.bigPlugin(); 22 console.log(options.switchingSize); 23 } 24 25 26 /* リサイズ時に実行する */ 27 $(window).on('resize', function(){ 28 width = window.innerWidth; 29 console.log(width); 30 console.log(options.switchingSize); 31 32 if(width < options.switchingSize){ 33 console.log("bigPlugin delete "); 34 console.log("smallPlugins add"); 35 } 36 else{ 37 console.log("smallPlugin delete"); 38 console.log("bigPlugin add"); 39 } 40 }); 41 42 }; 43 44}($));
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/03/30 11:47
2015/03/30 11:58
2015/03/30 14:40