| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 422 人关注过本帖
标题:我的切换图片效果都乱掉了......
只看楼主 加入收藏
dwqdaiwenqi
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-1-10
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
我的切换图片效果都乱掉了......
鼠标没有hover,都是正常切换,
一旦,hover之后,就乱套了.....
我想了很多,发现gogo()有问题。
解决不掉这个问题......。。。

<style type="text/css">
#place
{
    width:350px;
    height:251px;
    margin-left:200px;   
}
ul
{
    margin:0px;
    padding:0px;
    list-style-type:none;
    position:absolute;
    left: 457px;
    top: 255px;
    height: 28px;
}
ul li
{
    float:left;   
    width:25px;
    height:20px;
    margin-left:10px;
}
.bg1
{
    background-image:url(images/imagesshow/btn2.gif);   
}
.bg2
{
    background-image:url(images/imagesshow/btn.jpg);   
}
</style>
<script type="text/javascript">
window.onload=function()
{
    createPlace();
    time = setInterval("changeImg()",1000);
}
function createPlace()
{
    var place = document.getElementById("place");
    var showplace = document.createElement("img");
    showplace.setAttribute("src","images/imagesshow/big4.gif");
    showplace.setAttribute("id","showplace");
    place.appendChild(showplace);
   
    var rect = document.getElementById("rect");
    rectli = rect.getElementsByTagName("li");
    for(var i=0;i<rectli.length;i++)
    {
        rectli[i].setAttribute("class","bg1");   
    }
    rectli[0].setAttribute("class","bg2");
}
var count=0;//当前的src
var count2=1;//之后替换的src
var myar = [4,1,3,2];
function changeImg()
{   
    var showplace = document.getElementById("showplace");
    var source = showplace.getAttribute("src");
    if(count>3) count=0;
    if(count2>3) count2=0;
    var csource = source.replace(myar[count],myar[count2]);
    showplace.setAttribute("src",csource);   
    for(var j=0;j<4;j++)
    {
        rectli[j].setAttribute("class","bg1");
        rectli[j].onmouseout=function()
        {
            time = setInterval("changeImg()",1000);
        }
    }
    rectli[count2].setAttribute("class","bg2");
    count++;
    count2++;
}
function gogo(whichrect)
{
    clearInterval(time);
    var rect = document.getElementById("rect");
    rectli = rect.getElementsByTagName("li");
    for(var i=0;i<rectli.length;i++)
    {
        rectli[i].setAttribute("class","bg1");   
    }
    rectli[whichrect].setAttribute("class","bg2");
   
    var showplace = document.getElementById("showplace");
    var source = showplace.getAttribute("src");
    var csource = source.replace(myar[count],myar[whichrect]);
    count=whichrect;
    showplace.setAttribute("src",csource);
}
</script>
</head>
<body style="background-color:#000">
<div id="place">
</div>
<ul id="rect">
    <li onmouseover="gogo(0)"></li>
    <li onmouseover="gogo(1)"></li>
    <li onmouseover="gogo(2)"></li>
    <li onmouseover="gogo(3)"></li>
</ul>
搜索更多相关主题的帖子: 图片 gogo absolute position 
2012-01-10 18:14
dwqdaiwenqi
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-1-10
收藏
得分:0 
求解答。。。
2012-01-10 18:45
unbralocker
Rank: 2
等 级:论坛游民
帖 子:2
专家分:20
注 册:2012-1-13
收藏
得分:20 
var showplace = document.getElementById("showplace");  //改成 place
2012-01-13 14:53
快速回复:我的切换图片效果都乱掉了......
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020664 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved