<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title></title>
<base href="http://imgqun.qq.com/cgi-bin/" />
<style>
ul,li{ margin:0; padding:0; list-style-type:none;font-family: Arial;font-size: 12px;}
#sl li
{
background: url(img?uuid=202e5f624eae0ae0dd589c74ebb44d5696);
margin-top: 2px;
height: 30px;
line-height: 30px;
width: 200px;
}
#sl li a
{
color: #000066;
text-indent: 40px;
text-decoration: none;
font: bold 12px/100% '黑体,arial';
display: block;
zoom: 1;
height: 30px;
line-height: 30px;
border-right: 5px solid #000066;
background: url(img?uuid=20c8036e8ac98e139954a5dd98a45a6804) no-repeat 200px 0px;
}
#sl li a:hover
{
color: #fff;
font-size: 13px;
border-right: none;
letter-spacing: 1px;
}
</style>
</head>
<body>
<ul id="sl">
<li><a href="" title="" bg_y="0">;мē;壞!</a></li>
<li><a href="" title="" bg_y="-40">;мē;壞!</a></li>
<li><a href="" title="" bg_y="-80">;мē;壞!</a></li>
<li><a href="" title="" bg_y="-120">;мē;壞!</a></li>
<li><a href="" title="" bg_y="-140">;мē;壞!</a></li>
<li><a href="" title="" bg_y="-160">;мē;壞!</a></li>
<li><a href="" title="" bg_y="-180">;мē;壞!</a></li>
</ul>
<script>
var sl = {
on: function(o, type, fn) { o.attachEvent ? o.attachEvent('on' + type, function() { fn.call(o) }) : o.addEventListener(type, fn, false); return this },
$: function(o, tag) {
if (tag != undefined)
return (sl.$(o)).getElementsByTagName(tag);
return document.getElementById(o);
},
fx: function(form, to, s) {
var m = Math[form < to ? 'ceil' : 'floor'];
return function() { return form += m((to - form) * (s || 0.1)) };
},
move: function(who, attr, val, s, fn) {
var at = /backgroundPosition/i.test(attr);
var ft = parseInt(sl.css(who, attr)) || 0;
var fg = at ? (who.getAttribute("bg_y") || 0) + "px" : '';
if (this.css(who, attr) == undefined && at) ft = 200;
var fs = this.fx(ft, val,s);
clearInterval(who["time" + attr]);
who["time" + attr] = setInterval(function() {
var fe = fs();
who.style[attr] = fe + "px " + fg;
if (val == fe) { clearInterval(who["time" + attr]); }
}, 18);
return this;
},
css: function(who, key) {
if (who.style[key] != '') return who.style[key];
if (!!window.ActiveXObject) return who.currentStyle[key];
return document.defaultView.getComputedStyle(who, "")
.getPropertyValue(key.replace(/([A-Z])/g, "-$1").toLowerCase());
}
}
sl.on(window, 'load', function() {
var links = sl.$('sl', 'a');
for (var i = 0; i < links.length; i++) {
sl.on(links[i], 'mouseout', function() {
sl.move(this, 'textIndent', 40, 0.01).move(this, 'backgroundPosition', 200, 0.2);
}).on(links[i], 'mouseover', function() {
sl.move(this, 'textIndent', 45, 0.01).move(this, 'backgroundPosition', 0, 0.2);
});
}
});
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title></title>
<base href="http://imgqun.qq.com/cgi-bin/" />
<style>
ul,li{ margin:0; padding:0; list-style-type:none;font-family: Arial;font-size: 12px;}
#sl li
{
background: url(img?uuid=202e5f624eae0ae0dd589c74ebb44d5696);
margin-top: 2px;
height: 30px;
line-height: 30px;
width: 200px;
}
#sl li a
{
color: #000066;
text-indent: 40px;
text-decoration: none;
font: bold 12px/100% '黑体,arial';
display: block;
zoom: 1;
height: 30px;
line-height: 30px;
border-right: 5px solid #000066;
background: url(img?uuid=20c8036e8ac98e139954a5dd98a45a6804) no-repeat 200px 0px;
}
#sl li a:hover
{
color: #fff;
font-size: 13px;
border-right: none;
letter-spacing: 1px;
}
</style>
</head>
<body>
<ul id="sl">
<li><a href="" title="" bg_y="0">;мē;壞!</a></li>
<li><a href="" title="" bg_y="-40">;мē;壞!</a></li>
<li><a href="" title="" bg_y="-80">;мē;壞!</a></li>
<li><a href="" title="" bg_y="-120">;мē;壞!</a></li>
<li><a href="" title="" bg_y="-140">;мē;壞!</a></li>
<li><a href="" title="" bg_y="-160">;мē;壞!</a></li>
<li><a href="" title="" bg_y="-180">;мē;壞!</a></li>
</ul>
<script>
var sl = {
on: function(o, type, fn) { o.attachEvent ? o.attachEvent('on' + type, function() { fn.call(o) }) : o.addEventListener(type, fn, false); return this },
$: function(o, tag) {
if (tag != undefined)
return (sl.$(o)).getElementsByTagName(tag);
return document.getElementById(o);
},
fx: function(form, to, s) {
var m = Math[form < to ? 'ceil' : 'floor'];
return function() { return form += m((to - form) * (s || 0.1)) };
},
move: function(who, attr, val, s, fn) {
var at = /backgroundPosition/i.test(attr);
var ft = parseInt(sl.css(who, attr)) || 0;
var fg = at ? (who.getAttribute("bg_y") || 0) + "px" : '';
if (this.css(who, attr) == undefined && at) ft = 200;
var fs = this.fx(ft, val,s);
clearInterval(who["time" + attr]);
who["time" + attr] = setInterval(function() {
var fe = fs();
who.style[attr] = fe + "px " + fg;
if (val == fe) { clearInterval(who["time" + attr]); }
}, 18);
return this;
},
css: function(who, key) {
if (who.style[key] != '') return who.style[key];
if (!!window.ActiveXObject) return who.currentStyle[key];
return document.defaultView.getComputedStyle(who, "")
.getPropertyValue(key.replace(/([A-Z])/g, "-$1").toLowerCase());
}
}
sl.on(window, 'load', function() {
var links = sl.$('sl', 'a');
for (var i = 0; i < links.length; i++) {
sl.on(links[i], 'mouseout', function() {
sl.move(this, 'textIndent', 40, 0.01).move(this, 'backgroundPosition', 200, 0.2);
}).on(links[i], 'mouseover', function() {
sl.move(this, 'textIndent', 45, 0.01).move(this, 'backgroundPosition', 0, 0.2);
});
}
});
</script>
</body>
</html>
尤其是move函数详细些,移动开始快后来慢什么的,移动的原理是什么这能详细些吗?...
你的原创,你的讲解,期待...
o.attachEvent('on' + type, function() { fn.call(o) })
我感觉下面这样就可以了
o.attachEvent('on' + type, fn)
但是试了下 我的出不来效果 想问问楼主 这里为什么要fn.call(o)一下???
难道是mootools的bug??
addListener: function(type, fn){
if (type == 'unload'){
var old = fn, self = this;
fn = function(){
self.removeListener('unload', fn);
old();
};
} else {
collected[this.uid] = this;
}
if (this.addEventListener) this.addEventListener(type, fn, false);
else this.attachEvent('on' + type, fn);
return this;
}
zoom: 1;
是多余的吧 虽然看到很多人加这句 但是去掉之后 效果是一样的
这句有什么用吗??
who.style[attr] = fe + "px " + fg; 类似于
alert(33+'px'+44+'px')//弹出33px44px本来应该是错的 但为什么效果是对的呢?? 而且出去中间的+'px'反而会出错
真是不解 为什么啊~~