下面是一个完整的点击滚动js,但是我想把下面的js改一下,实现如果效果,当图片为第一张时,就不能再向左边滚动了,左边的按钮也不能点击了,当图片为最后一张时,就不再向右边滚动了,右边的按钮也不能点击了。各位好心人,请帮帮忙,好人有好报!!
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
<title>图片滚动效果+按钮控制左右滚动</title>
<style type="text/css"> 
a { color:#213f71; font-size:9pt; text-decoration:none;}
a:hover {color:#eb8923; }
/* product_img_roll */
.blk_18 {
overflow:hidden;
zoom:1;
font-size:12px;
border:1px solid #e3e3e3;
background:#f3f3f3;
width:692px;
margin-top:8px;
}
.blk_18 .pcont {
width:638px;
float:left;
overflow:hidden;
padding-left:5px;
}
.blk_18 .ScrCont {
width:32766px;
zoom:1;
margin-left:-5px;
}
.blk_18 #List1_1, .blk_18 #List2_1 {
float:left;
}
.blk_18 .LeftBotton, .blk_18 .RightBotton {
width:15px;
height:74px;
float:left;
background:url(http://www.365css.cn/example/guendongtupian/picr_1_01.gif) no-repeat;
}
.blk_18 .LeftBotton {
background-position: 0 0;
margin:8px 5px 0;
}
.blk_18 .RightBotton {
background-position: 0 -100px;
margin:8px 1px 10px 5px;
}
.blk_18 .LeftBotton:hover {
background-position: -20px 0;
}
.blk_18 .RightBotton:hover {
background-position: -20px -100px;
}
.blk_18 .pl img {
display:block;
cursor:pointer;
border:none;
margin:6px auto 1px auto;
}
.blk_18 .pl {
width:105px;
border:1px solid #f3f3f3;
float:left;
float:left;
text-align:center;
line-height:24px;
}
.blk_18 a.pl:hover {
border:1px solid #5dacec;
color:#5dacec;
background:#fff;
}
</style>
<script type="text/javascript"> 
//========================产品与服务==============================
//图片滚动列表 mengjia 070927
var Speed_1 = 10; //速度(毫秒)
var Space_1 = 20; //每次移动(px)
var PageWidth_1 = 107 * 6; //翻页宽度
var interval_1 = 5000; //翻页间隔时间
var fill_1 = 0; //整体移位
var MoveLock_1 = false;
var MoveTimeObj_1;
var MoveWay_1="right";
var Comp_1 = 0;
var AutoPlayObj_1=null;
function GetObj(objName){if(document.getElementById){return eval('document.getElementById("'+objName+'")')}else{return eval('document.all.'+objName)}}
function AutoPlay_1(){clearInterval(AutoPlayObj_1);AutoPlayObj_1=setInterval('ISL_GoDown_1();ISL_StopDown_1();',interval_1)}
function ISL_GoUp_1(){if(MoveLock_1)return;clearInterval(AutoPlayObj_1);MoveLock_1=true;MoveWay_1="left";MoveTimeObj_1=setInterval('ISL_ScrUp_1();',Speed_1);}
function ISL_StopUp_1(){if(MoveWay_1 == "right"){return};clearInterval(MoveTimeObj_1);if((GetObj('ISL_Cont_1').scrollLeft-fill_1)%PageWidth_1!=0){Comp_1=fill_1-(GetObj('ISL_Cont_1').scrollLeft%PageWidth_1);CompScr_1()}else{MoveLock_1=false}
AutoPlay_1()}
function ISL_ScrUp_1(){if(GetObj('ISL_Cont_1').scrollLeft<=0){GetObj('ISL_Cont_1').scrollLeft=GetObj('ISL_Cont_1').scrollLeft+GetObj('List1_1').offsetWidth}
GetObj('ISL_Cont_1').scrollLeft-=Space_1}
function ISL_GoDown_1(){clearInterval(MoveTimeObj_1);if(MoveLock_1)return;clearInterval(AutoPlayObj_1);MoveLock_1=true;MoveWay_1="right";ISL_ScrDown_1();MoveTimeObj_1=setInterval('ISL_ScrDown_1()',Speed_1)}
function ISL_StopDown_1(){if(MoveWay_1 == "left"){return};clearInterval(MoveTimeObj_1);if(GetObj('ISL_Cont_1').scrollLeft%PageWidth_1-(fill_1>=0?fill_1:fill_1+1)!=0){Comp_1=PageWidth_1-GetObj('ISL_Cont_1').scrollLeft%PageWidth_1+fill_1;CompScr_1()}else{MoveLock_1=false}
AutoPlay_1()}
function ISL_ScrDown_1(){if(GetObj('ISL_Cont_1').scrollLeft>=GetObj('List1_1').scrollWidth){GetObj('ISL_Cont_1').scrollLeft=GetObj('ISL_Cont_1').scrollLeft-GetObj('List1_1').scrollWidth}
GetObj('ISL_Cont_1').scrollLeft+=Space_1}
function CompScr_1(){if(Comp_1==0){MoveLock_1=false;return}
var num,TempSpeed=Speed_1,TempSpace=Space_1;if(Math.abs(Comp_1)<PageWidth_1/2){TempSpace=Math.round(Math.abs(Comp_1/Space_1));if(TempSpace<1){TempSpace=1}}
if(Comp_1<0){if(Comp_1<-TempSpace){Comp_1+=TempSpace;num=TempSpace}else{num=-Comp_1;Comp_1=0}
GetObj('ISL_Cont_1').scrollLeft-=num;setTimeout('CompScr_1()',TempSpeed)}else{if(Comp_1>TempSpace){Comp_1-=TempSpace;num=TempSpace}else{num=Comp_1;Comp_1=0}
GetObj('ISL_Cont_1').scrollLeft+=num;setTimeout('CompScr_1()',TempSpeed)}}
function picrun_ini(){
GetObj("List2_1").innerHTML=GetObj("List1_1").innerHTML;
GetObj('ISL_Cont_1').scrollLeft=fill_1>=0?fill_1:GetObj('List1_1').scrollWidth-Math.abs(fill_1);
GetObj("ISL_Cont_1").onmouseover=function(){clearInterval(AutoPlayObj_1)}
GetObj("ISL_Cont_1").onmouseout=function(){AutoPlay_1()}
AutoPlay_1();
}
</script>
</head>
<body>
<!-- picrotate_left start -->
<div class="blk_18"> <a class="LeftBotton" onmousedown="ISL_GoUp_1()" onmouseup="ISL_StopUp_1()" onmouseout="ISL_StopUp_1()" href="javascript:void(0);" target="_self"></a>
<div class="pcont" id="ISL_Cont_1">
<div class="ScrCont">
<div id="List1_1">
<!-- piclist begin -->
<a class="pl" href="#" ><img src="http://www.365css.cn/example/guendongtupian/1.jpg" alt="" width="96" height="72"/>图片一</a>
<a class="pl"href="#"> <img src="http://www.365css.cn/example/guendongtupian/2.jpg" alt="" width="96" height="72"/>图片而</a>
<a class="pl" href="#"><img src="http://www.365css.cn/example/guendongtupian/3.jpg" alt=""width="96" height="72"/>图片三</a>
<a class="pl" href="#"><img src="http://www.365css.cn/example/guendongtupian/4.jpg" alt="" width="96" height="72"/>图片四</a>
<a class="pl" href="#"><img src="http://www.365css.cn/example/guendongtupian/5.jpg" alt="" width="96" height="72"/>图片五</a>
<a class="pl" href="#"><img src="http://www.365css.cn/example/guendongtupian/6.jpg" alt="" width="96" height="72"/>图片六</a>
<a class="pl" href="#"><img src="http://www.365css.cn/example/guendongtupian/7.jpg" alt="" width="96" height="72"/>图片七</a>
<a class="pl" href="#" ><img src="http://www.365css.cn/example/guendongtupian/8.jpg" alt="" width="96" height="72"/>图片八</a>
<a class="pl" href="#" ><img src="http://www.365css.cn/example/guendongtupian/9.jpg" alt="" width="96" height="72"/>图片九</a>
<!-- piclist end -->
</div>
<div id="List2_1"></div>
</div>
</div>
<a class="RightBotton" onmousedown="ISL_GoDown_1()" onmouseup="ISL_StopDown_1()" onmouseout="ISL_StopDown_1()" href="javascript:void(0);" target="_self"></a> </div>
<div class="c"></div>
<script type="text/javascript">
<!--
picrun_ini()
//-->
</script>
<!-- picrotate_left end -->
</body>
</html>

解决方案 »

  1.   

    看下是不是你要的效果<!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>
    <meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
    <title>图片滚动效果+按钮控制左右滚动</title>
    <style type="text/css"> 
    a { color:#213f71; font-size:9pt; text-decoration:none;}
    a:hover {color:#eb8923; }
    /* product_img_roll */
    .blk_18 {
    overflow:hidden;
    zoom:1;
    font-size:12px;
    border:1px solid #e3e3e3;
    background:#f3f3f3;
    width:692px;
    margin-top:8px;
    }
    .blk_18 .pcont {
    width:638px;
    float:left;
    overflow:hidden;
    padding-left:5px;
    }
    .blk_18 .ScrCont {
    width:32766px;
    zoom:1;
    margin-left:-5px;
    }
    .blk_18 #List1_1, .blk_18 #List2_1 {
    float:left;
    }
    .blk_18 .LeftBotton, .blk_18 .RightBotton {
    width:15px;
    height:74px;
    float:left;
    background:url(http://www.365css.cn/example/guendongtupian/picr_1_01.gif) no-repeat;
    }
    .blk_18 .LeftBotton {
    background-position: 0 0;
    margin:8px 5px 0;
    }
    .blk_18 .RightBotton {
    background-position: 0 -100px;
    margin:8px 1px 10px 5px;
    }
    .blk_18 .LeftBotton:hover {
    background-position: -20px 0;
    }
    .blk_18 .RightBotton:hover {
    background-position: -20px -100px;
    }
    .blk_18 .pl img {
    display:block;
    cursor:pointer;
    border:none;
    margin:6px auto 1px auto;
    }
    .blk_18 .pl {
    width:105px;
    border:1px solid #f3f3f3;
    float:left;
    float:left;
    text-align:center;
    line-height:24px;
    }
    .blk_18 a.pl:hover {
    border:1px solid #5dacec;
    color:#5dacec;
    background:#fff;
    }
    </style>
    <script type="text/javascript"> 
    //========================产品与服务==============================
    //图片滚动列表 mengjia 070927
    var Speed_1 = 10; //速度(毫秒)var Space_1 = 20; //每次移动(px)var PageWidth_1 = 107 * 6; //翻页宽度var interval_1 = 5000; //翻页间隔时间var fill_1 = 0; //整体移位var MoveLock_1 = false;
    var MoveTimeObj_1;
    var MoveWay_1 = "right";
    var Comp_1 = 0;
    var AutoPlayObj_1 = null;
    function GetObj(objName)
    {
        if (document.getElementById)
        {
            return eval('document.getElementById("' + objName + '")')
        }
        else
        {
            return eval('document.all.' + objName)
        }
    }
    function AutoPlay_1()
    {
        clearInterval(AutoPlayObj_1);
        AutoPlayObj_1 = setInterval('ISL_GoDown_1();ISL_StopDown_1();', interval_1)
    }
    function ISL_GoUp_1()
    {
        if (MoveLock_1) return;
        clearInterval(AutoPlayObj_1);
        MoveLock_1 = true;
        MoveWay_1 = "left";
        MoveTimeObj_1 = setInterval('ISL_ScrUp_1();', Speed_1);
    }
    function ISL_StopUp_1()
    {
        if (MoveWay_1 == "right")
        {
            return
        };
        clearInterval(MoveTimeObj_1);
        if ((GetObj('ISL_Cont_1').scrollLeft - fill_1) % PageWidth_1 != 0)
        {
            Comp_1 = fill_1 - (GetObj('ISL_Cont_1').scrollLeft % PageWidth_1);
            CompScr_1()
        }
        else
        {
            MoveLock_1 = false
        }
        AutoPlay_1()
    }
    function ISL_ScrUp_1()
    {
        if (GetObj('ISL_Cont_1').scrollLeft <= 0)
        {
    return;
           // GetObj('ISL_Cont_1').scrollLeft = GetObj('ISL_Cont_1').scrollLeft + GetObj('List1_1').offsetWidth
        }
        GetObj('ISL_Cont_1').scrollLeft -= Space_1
    }
    function ISL_GoDown_1()
    {
        clearInterval(MoveTimeObj_1);
        if (MoveLock_1) return;
        clearInterval(AutoPlayObj_1);
        MoveLock_1 = true;
        MoveWay_1 = "right";
        ISL_ScrDown_1();
        MoveTimeObj_1 = setInterval('ISL_ScrDown_1()', Speed_1)
    }
    function ISL_StopDown_1()
    {
        if (MoveWay_1 == "left")
        {
            return
        };
        clearInterval(MoveTimeObj_1);
        if (GetObj('ISL_Cont_1').scrollLeft % PageWidth_1 - (fill_1 >= 0 ? fill_1 : fill_1 + 1) != 0)
        {
            Comp_1 = PageWidth_1 - GetObj('ISL_Cont_1').scrollLeft % PageWidth_1 + fill_1;
            CompScr_1()
        }
        else
        {
            MoveLock_1 = false
        }
        AutoPlay_1()
    }
    function ISL_ScrDown_1()
    {
        if (GetObj('ISL_Cont_1').scrollLeft >= GetObj('List1_1').scrollWidth / 2)
        {
    return;
            // GetObj('ISL_Cont_1').scrollLeft = GetObj('ISL_Cont_1').scrollLeft - GetObj('List1_1').scrollWidth
        }
        GetObj('ISL_Cont_1').scrollLeft += Space_1
    }
    function CompScr_1()
    {
        if (Comp_1 == 0)
        {
            MoveLock_1 = false;
            return
        }
        var num, TempSpeed = Speed_1,
            TempSpace = Space_1;
        if (Math.abs(Comp_1) < PageWidth_1 / 2)
        {
            TempSpace = Math.round(Math.abs(Comp_1 / Space_1));
            if (TempSpace < 1)
            {
                TempSpace = 1
            }
        }
        if (Comp_1 < 0)
        {
            if (Comp_1 < -TempSpace)
            {
                Comp_1 += TempSpace;
                num = TempSpace
            }
            else
            {
                num = -Comp_1;
                Comp_1 = 0
            }
            GetObj('ISL_Cont_1').scrollLeft -= num;
            setTimeout('CompScr_1()', TempSpeed)
        }
        else
        {
            if (Comp_1 > TempSpace)
            {
                Comp_1 -= TempSpace;
                num = TempSpace
            }
            else
            {
                num = Comp_1;
                Comp_1 = 0
            }
            GetObj('ISL_Cont_1').scrollLeft += num;
            setTimeout('CompScr_1()', TempSpeed)
        }
    }
    function picrun_ini()
    {
        //GetObj("List2_1").innerHTML = GetObj("List1_1").innerHTML;
        GetObj('ISL_Cont_1').scrollLeft = fill_1 >= 0 ? fill_1 : GetObj('List1_1').scrollWidth - Math.abs(fill_1);
        GetObj("ISL_Cont_1").onmouseover = function ()
        {
            clearInterval(AutoPlayObj_1)
        }
        GetObj("ISL_Cont_1").onmouseout = function ()
        {
            AutoPlay_1()
        }
        AutoPlay_1();
    }
    </script>
    </head>
    <body>
    <!-- picrotate_left start -->
    <div class="blk_18"> 
    <a class="LeftBotton" onmousedown="ISL_GoUp_1()" onmouseup="ISL_StopUp_1()" onmouseout="ISL_StopUp_1()" href="javascript:void(0);" target="_self"></a>
    <div class="pcont" id="ISL_Cont_1">
    <div class="ScrCont">
    <div id="List1_1">
    <!-- piclist begin -->
    <a class="pl" href="#" ><img src="http://www.365css.cn/example/guendongtupian/1.jpg" alt="" width="96" height="72"/>图片一</a>
    <a class="pl"href="#"> <img src="http://www.365css.cn/example/guendongtupian/2.jpg" alt="" width="96" height="72"/>图片而</a>
    <a class="pl" href="#"><img src="http://www.365css.cn/example/guendongtupian/3.jpg" alt=""width="96" height="72"/>图片三</a>
    <a class="pl" href="#"><img src="http://www.365css.cn/example/guendongtupian/4.jpg" alt="" width="96" height="72"/>图片四</a>
    <a class="pl" href="#"><img src="http://www.365css.cn/example/guendongtupian/5.jpg" alt="" width="96" height="72"/>图片五</a>
    <a class="pl" href="#"><img src="http://www.365css.cn/example/guendongtupian/6.jpg" alt="" width="96" height="72"/>图片六</a>
    <a class="pl" href="#"><img src="http://www.365css.cn/example/guendongtupian/7.jpg" alt="" width="96" height="72"/>图片七</a>
    <a class="pl" href="#" ><img src="http://www.365css.cn/example/guendongtupian/8.jpg" alt="" width="96" height="72"/>图片八</a>
    <a class="pl" href="#" ><img src="http://www.365css.cn/example/guendongtupian/9.jpg" alt="" width="96" height="72"/>图片九</a>
    <!-- piclist end -->
    </div>
    <div id="List2_1"></div>
    </div>
    </div>
    <a class="RightBotton" onmousedown="ISL_GoDown_1()" onmouseup="ISL_StopDown_1()" onmouseout="ISL_StopDown_1()" href="javascript:void(0);" target="_self"></a> 
    </div>
    <div class="c"></div>
    <script type="text/javascript">
    <!--
    picrun_ini()
    //-->
    </script>
    <!-- picrotate_left end -->
    </body>
    </html>
      

  2.   


    kongxh1218 你太厉害了, 谢谢你吖!!