2009-05-27から1日間の記事一覧

複数の画像をスロットマシーンの用に横に回転させる

回転させるアルゴリズムがよくない。 あとで、なおそうっと! <title>Images</title> <style type="text/css"> #waku0 { overflow:auto; width:600px; height:90px; border:1px red solid;} #waku0 img { border:0px none; width:120px; height:90px; } </style> <div id="waku0"> </div>

ノードの子を全て削除する

function clearChildNodes(node) { while (node.hasChildNodes()) node.removeChild(node.firstChild); return node; }

1つ次のノードを取得する

function getNextNode (node) { var n; if (n = node.firstChild) return n; do if (n = node.nextSibling) return n; while (node = node.parentNode); return null; }

1つ前のノードを取得する

function getPreviousNode (node) { var n; if (n = node.previousSibling) { while (n.hasChildNodes()) n = n.lastChild; return n; } return node.parentNode; }

要素のテキストを取得する

//@cc_on function getElementText (e) { return e./*@if (@_jscript) innerText @else@*/ textContent /*@end@*/; } function getNodeText(node) { return node.firstChild.nodeValue; }

指定した条件で、親の要素を取得する

function getParent(node, type, val) { return node ? (val == node[type]) ? node: arguments.callee(node.parentNode, type, val): null; }

Cookieを取得する

function getCookie(name) { var value; name = encodeURIComponent( name ).replace( /([.*()])/g, '\\$1' ); value = document.cookie.match( RegExp ( name + '\\s*=\\s*(.*?)(?:[\\s;,]|$)' ) ); return value ? decodeURIComponent( value[1] ) : ''; }

Cookieを保存する

function setCookie(name, value, day, path, domain) { return document.cookie = encodeURIComponent( name ) + '=' + encodeURIComponent( value ) + '; ' + 'expires=' + new Date( (new Date) - 86400000 * -day ).toUTCString() + '; ' + ( path ? 'pa…

要素の座標を取得する

function getPosition(node) { var x = 0, y = x; do { x += node.offsetLeft; y += node.offsetTop; } while (node = node.offsetParent) return {x: x, y:y}; }

テーブルの行をランダムに並び替える

function randomRows(tableId) { var i = 0 var o; var table = document.getElementById(tableId) var tbody = table.getElementsByTagName('tbody')[0]; var r; while (o = tbody.childNodes[i]) { if (3 == o.nodeType) { tbody.removeChild(o); } else {…

そういえば炎上すれすれ?!

そこのブログのアドレスを書くつもりは無いが、気になってみてる。過去に、JavaScriptの事で、そいつに回答したことがあるんだよなぁ〜。IT関連の仕事をしているというのだが、なんというか・・・・それで飯をくっているってのが、信じられない。レベルが上…