.ready() waits for .getScript()
訳:.ready()は.getScript()を待つよ!
しまった。まんますぎた。
This addition would allow users to dynamically load remote scripts and have them be executed before the main flow of the application commences.
This is very useful functionality, and similar to the features provided by Dojo, Mochikit, and OpenJSAN.
A solution would allow users to do the following:
$.getScript("http://foo.com/bar.js"); $.getScript("/my/test.js"); $(document).ready(function(){ bar(); // use bar from bar.js test(); // use test from test.js });This proposal currently doesn’t call for the scripts in getScript to be loaded synchronously - meaning that the above test.js could be loaded, and executed, before bar.js.
今まで知らんかったっっっ。
とりあえず、これで毎回プラグイン追加する度にscriptタグ増やさなくてよいわけですね!
てかこのページに書いてあること、他にもけっこう知らなかったことが・・・。
・・・て、この機能1.2.6現在まだ未実装っぽいな。
んでもまぁ、
$.getScript("/my/test.js", function(){ $(document).ready(function(){ test(); // use test from test.js }); });
って形で.ready()を.getScript()のコールバックにしとけば一応期待通りの動作にはなるっぽいね。
でもこの方法だと複数個.getScript()しときたい場合、ネストしまくってキモイコードになりそだから今のところ素直にscriptタグで読み込むのが一番ってとこでしょーか。
秀丸エディタでRubyをマクロにして使う - Rubyの魔神 - はてな?Rubyグループ
1.まず、上記をダウンロードして秀丸のフォルダに保存し、マクロ登録します。
2.秀丸で処理したいソースを開きます。
3.上部に以下を書きます(行番号をつける例です)i = 1 DATA.each{ |d| puts i.to_s + ":" + d i += 1 } __END__4.マクロ実行をすると別秀丸でマクロ処理されたものが開かれます。
これはすごい。
便利すぎる。
Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/modPukiWiki/plugin/notice.inc.php on line 14
Deprecated: Function split() is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/modPukiWiki/lib/func.php on line 75
Deprecated: Function split() is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/modPukiWiki/lib/func.php on line 75
Deprecated: Function ereg() is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/modPukiWiki/plugin/ref.inc.php on line 207
Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/modPukiWiki/plugin/region.inc.php on line 14
- 08/12/05 修正
- return $(this) → return this に。
古いのだとメソッドチェーンしたときにたぶんまずいことになる。
スクロールについてきてぬるぬる動くやつをちょと変更。
- がちゃがちゃとスクロールしまくるとたまに妙な位置で止まるので(もっかいスクロールすれば治るけど)、定期的に今の位置を確認しておかしな場所に居れば本来居るべき場所に動くようにした。
- ということでオプションに『check』を追加。0にしたら定期チェック無しに。
- Safariで挙動がおかしな場合があるのでposition:fixedでお茶濁し。
必要なもの
サンプル
オプション
- wait(デフォルト値:100)
- スクロールしてから動き出すまで(ms)
- minDuration(デフォルト値:100)
- アニメーションの最小時間(ms)
- check(デフォルト値:1000)
- 定期チェックの間隔(ms)
0にするとチェック無しに。
ソース
…
$.fn.floating = function(options){ options = $.extend({ wait: 100, minDuration: 100, check: 1000 }, options); return this.each(function(){ var $this = $(this); //safariはfixedでお茶濁し if($.browser.safari){ $this.css("position", "fixed"); return true;//continue } var boxTop = function(){return $this.offset().top}; var startTop = boxTop(); var timer, checkTimer; var scrollTop, nowTop, targetTop, duration; var d = document, w = window; var getPosTop = function(){ scrollTop = d.body.scrollTop || d.documentElement.scrollTop; nowTop = boxTop(); targetTop = scrollTop + startTop; duration = Math.max(options.minDuration, Math.abs(targetTop - nowTop)); }; var scrollAnimation = function(){ $this .animate({ top: targetTop + "px" }, duration, function(){ timer = 0; }); }; $(w) .scroll(function(){ if(timer) return; timer = w.setTimeout(function(){ getPosTop(); scrollAnimation(); }, options.wait); }); //定期的にチェック checkが0ならスルー if(options.check) checkTimer = w.setInterval(function(){ if(timer) return; getPosTop(); if(nowTop == targetTop) return; scrollAnimation(); }, options.check); }); }; |