两段代码放一起,另一个就无效了。
<script type="text/javascript">
$(".list li a").click(function(){
$(".list li a").removeClass("sel");
$(this).addClass("sel");
$(".list li a").css({background:"none"})
$(".sel").css({background:"#383838"})
})
$(".list li a").active(function(){
$(".list li a").not(".sel").css({background:"none"})
$(this).css({background:"#383838"})
})
</script>
<script type="text/javascript">
//获取id
function $ (id)
{
return typeof id === "string" ? document.getElementById(id) : id;
}
//获取tagName
function $$ (elem, oParent)
{
return (oParent || document).getElementsByTagName(elem);
}
//获取class
function $$$ (className, oParent)
{
var aClass = [];
var reClass = new RegExp("(//s|^)" + className + "($|//s)");
var aElem = $$("*", oParent);
for (var i = 0; i < aElem.length; i++) reClass.test(aElem[i].className) && aClass.push(aElem[i]);
return aClass
}
//初始化对象
function Roll ()
{
this.initialize.apply(this, arguments)
}
Roll.prototype =
{
initialize: function (obj)
{
var _this = this;
this.obj = $(obj);
this.oUp = $$$("up", this.obj)[0];
this.oDown = $$$("down", this.obj)[0];
this.oList = $$$("list", this.obj)[0];
this.aItem = this.oList.children;
this.timer = null;
this.iNow = 0;
this.iHeight = this.aItem[0].offsetHeight;
this.oUp.onclick = function ()
{
_this.up()
};
this.oDown.onclick = function ()
{
_this.down()
}
},
up: function ()
{
this.oList.insertBefore(this.aItem[this.aItem.length - 1], this.oList.firstChild);
this.oList.style.top = -this.iHeight + "px";
this.doMove(0)
},
down: function ()
{
this.doMove(-this.iHeight, function ()
{
this.oList.appendChild(this.aItem[0]);
this.oList.style.top = 0;
})
},
doMove: function (iTarget, callBack)
{
var _this = this;
clearInterval(this.timer)
this.timer = setInterval(function ()
{
var iSpeed = (iTarget - _this.oList.offsetTop) / 5;
iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);
_this.oList.offsetTop == iTarget ? (clearInterval(_this.timer), callBack && callBack.apply(_this)) :
_this.oList.style.top = iSpeed + _this.oList.offsetTop + "px"
}, 30)
}
};
window.onload = function ()
{
new Roll("side");
};
</script>
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
https://www.v2ex.com/t/92514
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.