Js滚动效果
时间:2011-04-15 来源:X龙
1.Marquee.js
http://www.popub.net/script/MSClass.html这个js功能比较齐全,几乎所有效果都有,比较好用。
2. var scrollElem;
var stopscroll;
var stoptime;
var preTop;
var leftElem;
var currentTop;
var marqueesHeight;
function marque(width, height, marqueName, marqueCName)
{
try
{
marqueesHeight = height;
stopscroll = false;
scrollElem = document.getElementById(marqueName);
with (scrollElem)
{
style.width = width;
style.height = marqueesHeight;
style.overflow = 'hidden';
noWrap = true;
}
scrollElem.onmouseover = new Function('stopscroll = true');
scrollElem.onmouseout = new Function('stopscroll = false');
preTop = 0;
currentTop = 0;
stoptime = 0;
leftElem = document.getElementById(marqueCName);
scrollElem.appendChild(leftElem.cloneNode(true));
init_srolltext();
} catch (e) { }
}
function init_srolltext()
{
scrollElem.scrollTop = 0;
setInterval('scrollUp()', 20);
}
function scrollUp()
{
if (stopscroll) return;
currentTop += 1;
if (currentTop == marqueesHeight + 1)
{
stoptime += 1;
currentTop -= 1;
if (stoptime == (marqueesHeight) * 4)
{//停顿时间
currentTop = 0;
stoptime = 0;
}
} else
{
preTop = scrollElem.scrollTop;
scrollElem.scrollTop += 1;
if (preTop == scrollElem.scrollTop)
{
scrollElem.scrollTop = marqueesHeight;
scrollElem.scrollTop += 1;
}
}
}
// marque(810, 30, "innerul", "innerul")
3.单行滚动,一行只有一个元素。
function AutoScrollUp(obj){$(obj).find("ul:first").animate({
marginTop:"-33px"
},500,function(){
$(this).css({marginTop:"0px"}).find("li:first").appendTo(this);
});
}
$(document).ready(function(){
setInterval('AutoScrollUp("#innerul")',2000);
})
相关阅读 更多 +