您的位置:首页 > Web前端 > JavaScript

js仿土豆视频滚动菜单

2008-05-07 00:00 239 查看
脚本之家 www.jb51.net 仿土豆视频滚动菜单

ul{margin:0;padding:0;list-style:none;width:100000px}
li{margin:0;padding:0;width:100px;height:100px;display:block;float:left;margin-right:5px;background:#009900}
#img_bag{width:640px;height:100px;background:#FF9900;margin:0 auto;}
#img_bag a{float:left;width:20px;display:block;height:20px;font-weight:bold;}
#img_bag #img{width:600px;height:100px;background:#ccc;overflow:hidden;float:left}
#scrollBar{width:600px;height:20px;background:#FF0000;margin:0 auto;position:relative}
#scroll{width:30px;height:20px;background:#000;cursor:pointer;position:absolute;}




<<
















>>






function $(obj){return document.getElementById(obj)}
var maxWidth=$("img").getElementsByTagName("ul")[0].getElementsByTagName("li").length*105;
var isScroll=false;
var modiLeft;
$("scroll").onmousedown=function(evt){
isScroll=true;
evt=(evt)?evt:((window.event)?window.event:null);
if(evt.offsetX){
modiLeft=parseInt(evt.offsetX)
}
else{modiLeft=parseInt(evt.layerX)}
}
document.onmouseup=function(){
isScroll=false;
}
document.onmousemove=function(evt){
evt=(evt)?evt:((window.event)?window.event:null);
if(evt&&isScroll){
$("scroll").style.left=parseInt(evt.clientX)-parseInt($("scrollBar").offsetLeft)-modiLeft+"px";
if(parseInt($("scroll").style.left)570){$("scroll").style.left=570+"px"}
$("img").scrollLeft=parseInt($("scroll").style.left)*((maxWidth-600)/570);
}
}
var targetx = 200;//一次滚动距离
var dx;
var a=null;
function moveLeft(){
var le=parseInt($("img").scrollLeft);
if(le>200){
targetx=parseInt($("img").scrollLeft)-200;
}
else{targetx=parseInt($("img").scrollLeft)-le-1}
scLeft();
}
function scLeft(){
dx=parseInt($("img").scrollLeft)-targetx;
$("img").scrollLeft-=dx*.3;
$("scroll").style.left=parseInt($("img").scrollLeft)*(570/(maxWidth-600))+"px";
if(parseInt($("scroll").style.left)570){$("scroll").style.left=570+"px"}
clearScroll=setTimeout(scLeft,50);
if(dx*.3
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: