[JavaScript]hover関数を修正
- 2007-12-09
- カテゴリ: Client Side
- タグ: Tips JavaScript jQuery hover 修正 トラックバック
以前、jQueryのhover関数を移植したことがあったのだが、実地で使ってみたらいろいろとバグが出たので修正。
jQueryのソースでは、
// Traverse up the tree while ( p && p != this ) try { p = p.parentNode; } catch(e) { p = this; }; // If we actually just moused on to a sub-element, ignore it if ( p == this ) return false;
となっているコードを、大幅に省略して
do if (p == elm) return false; while (p = p.parentNode);
としていたんだが、やはり横着するとよくないらしい。ところどころでバグる。
スポンサーサイト
[JavaScript]jQuery#hover()を移植してみた
- 2007-11-22
- カテゴリ: Client Side
- タグ: Tips JavaScript hover prototype.js jQuery
[追記(2007-12-09)]バグが出たので、修正版を書いて別のエントリーで公開しました。
[追記(2007-11-23)] 改善案を思いついたので書き換え。jQueryの原型をとどめなくなった。
jQueryのhoverメソッドが便利です。↓こんな感じに使います。
$('#example').hover( function() { this._message = document.createElement('span'); this._message.innerHTML = 'Let\'s hover.'; this.appendChild(this._message); this.style.backgroundColor = 'yellow'; }, function() { this.removeChild(this._message); this.style.backgroundColor = 'white'; } );
[JavaScript]jQueryに入門
- 2007-10-20
- カテゴリ: Client Side
- タグ: JavaScript Tips jQuery 入門
jQueryに入門してみましたよっていう話。jQueryの入門記事ではないのであしからず。
以前からjQueryの噂は聞いていたし、ちょこちょことは見たこともあったのだが、なんとなくいい機会なので本格的に勉強してみることにした。
以下はその雑感。