美化Title的新選擇
- Posted by Beata on 三月 16th, 2006 filed in Blog, javascript
就是Beata這個站目前所使用的Title美化,如果連結有設置title屬性的話,那麼滑鼠移到連結之上便會產生一個紅色的小說明欄。
這份title美化的JS是基於prototype-lite這套JS原型所誕生的。
只要是網頁都能用,但須下載moo.fx,因為需要使用到其中的prototype.lite.js檔案。
如果已安裝過Ajax Comments-Reply就不用再下載moo.fx了。
去除prototype.lite的JS部份,檔案大小差不多1K左右吧~
再加上prototype.lite可以做很多有趣的事情,挺划算的!
CSS部份:
-
#tip{padding:4px 10px;border-color:#F00;display: none;background: #900;color: #FFF;position: absolute;z-index: 1000;-moz-border-radius:7px 7px 7px 0;opacity:0.7;filter:alpha(opacity=70)}
-
#tip p{opacity:1;filter:alpha(opacity=100)}
JS部份:
請存成JS檔連同prototype.lite.js一起引入文件開頭標籤之內
e.g:
<script src= "prototype.lite.js "></script>
<script src= "tip.js"></script>(安裝過Ajax Comments-Reply 只需加上這句即可)
或直接下載 tip.js
-
var D = document;
-
Tip = {
-
act: function() {
-
var es = D.getElementsByTagName(‘a’);
-
var c = $(‘tip’);
-
if (!c) {
-
var c = D.createElement(‘div’);
-
c.setAttribute(‘id’, ‘tip’);
-
D.getElementsByTagName(‘body’)[0].appendChild(c);
-
}
-
$c(es).each(
-
function(e) { var t = e.getAttribute(‘title’);
-
if (t) {
-
e.setAttribute(‘tip’, t);
-
e.removeAttribute(‘title’);
-
var p = Position.cumulativeOffset(e);
-
e.onmouseover = function() {
-
c.style.left = (p[0]+10)+‘px’;
-
c.style.top = (p[1]+30)+‘px’;
-
Tip.display(c, e.getAttribute(‘tip’));
-
};
-
e.onmouseout = function() {Tip.display(c)};}
-
});
-
},
-
-
display: function(c, t) {
-
if (t) {
-
c.innerHTML = ‘<p>’+t+‘</p>’;
-
c.style.display = ‘block’;
-
_O(c, 800).custom(0, 0.8);
-
} else {
-
c.innerHTML = ”;
-
c.style.display = ‘none’;
-
}
-
}
-
}
-
function _O(e, t) {
-
if (!t) t = 500;
-
var ef = new fx.Opacity(e, {duration: t, onComplete:function(){}});
-
return ef;
-
}
-
window.onload = Tip.act;
七月 20th, 2006 at 2:52 下午
非常感谢
懒懒猫一点都不懒
七月 20th, 2006 at 2:55 下午
你的友情链接是怎么做的,其实我更想问那个,--! 呵呵 懒懒猫 谢谢
十二月 2nd, 2006 at 5:04 下午
:注意:
挖!!
真是棒