| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 624 人关注过本帖
标题:为什么不能切换相应的颜色背景
只看楼主 加入收藏
rao3324180
Rank: 2
等 级:论坛游民
帖 子:8
专家分:10
注 册:2010-6-15
结帖率:50%
收藏
 问题点数:0 回复次数:3 
为什么不能切换相应的颜色背景
请大家帮我看看.累死我了.奋斗了10多个小时了.头都快爆炸了.检查了一个多小时了.还是不知道哪里出错了.
好心的朋友们帮下忙..希望醒来能有满意的答复.我敢肯定是slideshow()函数里出问题了.
睡觉去了
程序代码:
<html>
    <head>
        <style type="text/css">
*{margin:0;padding:0;}
ul{list-style:none outside none;}
img{border:none;display:block;}
a{text-decoration:none;}
#navigation{
    width:500px;
    margin:33px auto;
    border:1px solid orange;
    overflow:hidden;
    height:680px;
}
#naviContent{
    width:220px;
    float:right;
}
#naviContent li{
    width:220px;
    height:44px;
    display:block;
    float:left;
    clear:both;
    overflow:hidden;
    border-bottom:1px solid #ccc;
}
#naviContent span{
    display:block;
    width:200px;
    text-align:center;
    font-size:13px;
    line-height:20px;
    color:#838684;
}
#naviContent span strong{
    color:#4a4c4a;
}
#naviImage{
    width:270px;
    border:1px solid red;
    height:680px;
    overflow:hidden;
    position:relative;
}
#image_1{
    background:blue;
    width:270px;
    height:180px;
}
#image_2{
    background:yellow;
    width:270px;
    height:180px;
}
#image_3{
    background:red;
    width:270px;
    height:180px;
}
#image_4{
    background:green;
    width:270px;
    height:180px;
}
        </style>
        <script type="text/javascript">
function moveMessage(elementID,final_x,final_y,interval){
    var elem = document.getElementById(elementID);
    if(elem.movement){
        clearTimeout(elem.movement);
    }
    var xpos = parseInt(elem.style.left);
    var ypos = parseInt(elem.style.top);
    if(xpos == final_x && ypos == final_y){
        return true;
    }
    if(xpos < final_x){
        var dist = Math.ceil((final_x - xpos)/10);
        xpos = xpos + dist;
    }
    if(xpos > final_x){
        var dist = Math.ceil((xpos - final_x)/10);
        xpos = xpos - dist;
    }
    if(ypos < final_y){
        var dist = Math.ceil((final_y - ypos)/10);
        ypos = ypos + dist;
    }
    if(ypos > final_y){
        var dist = Math.ceil((ypos - final_y)/10);
        ypos = ypos - dist;
    }
    elem.style.left = xpos + "px";
    elem.style.top = ypos + "px";
    var repeat = "moveMessage('"+elementID+"',"+final_x+","+final_y+","+interval+")";
    elem.movement = setTimeout(repeat,interval)
}
function slideshow(){
    for(var i=1; i<4; i++){
    var slideshow = document.getElementById("image_"+i);
    slideshow.style.position = "absolute";
    slideshow.style.left = "0px";
    slideshow.style.top = "0px";
    var list = document.getElementById("list");
    var links = list.getElementsByTagName("a");
    links[0].onmouseover = function(){
        moveMessage("image_1",0,0,10);
    }
    links[1].onmouseover = function(){
        moveMessage("image_2",270,0,10);
    }
    links[2].onmouseover = function(){
        moveMessage("image_3",540,0,10);
    }
    links[3].onmouseover = function(){
        moveMessage("image_4",-820,0,10);
    }
    }
}
window.onload = slideshow;           

        </script>
    </head>
    <body>
        <div id="navigation">
            <div id="naviContent">
                <ul id="list">
                    <li><a href=""><span><strong>蓝色</strong></span><span>这是蓝色ss!</span></a></li>
                    <li><a href=""><span><strong>黄色</strong></span><span>这是黄色!</span></a></li>
                    <li><a href=""><span><strong>红色</strong></span><span>这是红色!</span></a></li>
                    <li><a href=""><span><strong>绿色</strong></span><span>这是绿色!</span></a></li>
                </ul>
            </div>
            <div id="naviImage">
                <a href=""><img src="images/blue.gif" id="image_1" /></a>
                <a href=""><img src="images/yellow.gif" id="image_2" /></a>
                <a href=""><img src="images/red.gif" id="image_3" /></a>
                <a href=""><img src="images/green.gif" id="image_4" /></a>
            </div>
        </div>
    </body>
</html>

搜索更多相关主题的帖子: 颜色 
2010-08-08 05:40
gulimeksoft
Rank: 4
等 级:业余侠客
威 望:4
帖 子:53
专家分:208
注 册:2010-8-5
收藏
得分:0 
因为涉及到图片的层叠位置,一个在上面,一个在下面,下面那个图像如果移动,被上面的图片挡住了,是看不到效果的
你把overflow:hidden这个属性去了,可以看到图片移出被挡住位置后的效果
这句换成这个
  if(xpos == final_x && ypos == final_y){
   
    elem.style.left=0;
    elem.style.top=0;
        return false;
    }
可以设置移动后返回原来位置,这样你才可以重复移动
2010-08-08 14:25
rao3324180
Rank: 2
等 级:论坛游民
帖 子:8
专家分:10
注 册:2010-6-15
收藏
得分:0 
以下是引用gulimeksoft在2010-8-8 14:25:12的发言:

因为涉及到图片的层叠位置,一个在上面,一个在下面,下面那个图像如果移动,被上面的图片挡住了,是看不到效果的
你把overflow:hidden这个属性去了,可以看到图片移出被挡住位置后的效果
这句换成这个
  if(xpos == final_x && ypos == final_y){
   
    elem.style.left=0;
    elem.style.top=0;
        return false;
    }
可以设置移动后返回原来位置,这样你才可以重复移动
好像还是不行啊
2010-08-08 16:17
gulimeksoft
Rank: 4
等 级:业余侠客
威 望:4
帖 子:53
专家分:208
注 册:2010-8-5
收藏
得分:0 
程序代码:
<html>
    <head>
        <style type="text/css">
*{margin:0;padding:0;}
ul{list-style:none outside none;}
img{border:none;display:block;}
a{text-decoration:none;}
#navigation{
    width:500px;
    margin:33px auto;
    border:1px solid orange;

 
    height:680px;
}
#naviContent{
    width:220px;
    float:right;
}
#naviContent li{
    width:220px;
    height:44px;
    display:block;
    float:left;
    clear:both;

    border-bottom:1px solid #ccc;
}
#naviContent span{
    display:block;
    width:200px;
    text-align:center;
    font-size:13px;
    line-height:20px;
    color:#838684;
}
#naviContent span strong{
    color:#4a4c4a;
}
#naviImage{
    width:270px;
    border:1px solid red;
    height:680px;

    position:relative;
}
#image_1{
    background:blue;
    width:270px;
    height:180px;
}
#image_2{
    background:yellow;
    width:270px;
    height:180px;
}
#image_3{
    background:red;
    width:270px;
    height:180px;
}
#image_4{
    background:green;
    width:270px;
    height:180px;
}
        </style>
        <script type="text/javascript">
var i=0;
function moveMessage(elementID,final_x,final_y,interval){
    var elem = document.getElementById(elementID);
    if(elem.movement){
        clearTimeout(elem.movement);
    }
    var xpos = parseInt(elem.offsetLeft);
    var ypos = parseInt(elem.offsetTop);
    if(xpos == final_x && ypos == final_y){
   
    elem.style.left=0;
    elem.style.top=0;
        return false;
    }
    if(xpos < final_x){
        var dist = Math.ceil((final_x - xpos)/10);
        xpos = xpos + dist;
    }
    if(xpos > final_x){
        var dist = Math.ceil((xpos - final_x)/10);
        xpos = xpos - dist;
    }
    if(ypos < final_y){
        var dist = Math.ceil((final_y - ypos)/10);
        ypos = ypos + dist;
    }
    if(ypos > final_y){
        var dist = Math.ceil((ypos - final_y)/10);
        ypos = ypos - dist;
    }

    elem.style.left = xpos + "px";
    elem.style.top = ypos + "px";
    var repeat = "moveMessage('"+elementID+"',"+final_x+","+final_y+","+interval+")";
    elem.movement = setTimeout(repeat,interval)
}
function slideshow(){
    for(var i=1; i<4; i++){
    var slideshow = document.getElementById("image_"+i);
    slideshow.style.position = "absolute";
    slideshow.style.left = "0px";
    slideshow.style.top = "0px";
    var list = document.getElementById("list");
    var links = list.getElementsByTagName("a");
    }
    links[0].onmouseover = function(){
        moveMessage("image_1",500,0,10);
    }
    links[1].onmouseover = function(){
        moveMessage("image_2",570,0,10);
    }
    links[2].onmouseover = function(){
        moveMessage("image_3",540,0,10);
    }
    links[3].onmouseover = function(){
        moveMessage("image_4",520,0,10);
    }
}
window.onload = slideshow;           

        </script>
    </head>
    <body>
        <div id="navigation">
            <div id="naviContent">
                <ul id="list">
                    <li><a onmouseover="moveMessage("image_1",0,0,10)" href=""><span ><strong>蓝色</strong></span><span>这是蓝色ss!</span></a></li>
                    <li><a onmouseover="moveMessage("image_1",0,0,10)" href=""><span><strong>黄色</strong></span><span>这是黄色!</span></a></li>
                    <li><a href=""><span><strong>红色</strong></span><span>这是红色!</span></a></li>
                    <li><a href=""><span><strong>绿色</strong></span><span>这是绿色!</span></a></li>
                </ul>
            </div>
             <div id="naviImage">
                <a href=""><img src="images/blue.gif" id="image_1" /></a>
                <a href=""><img src="images/yellow.gif" id="image_2" /></a>
                <a href=""><img src="images/red.gif" id="image_3" /></a>
                <a href=""><img src="images/green.gif" id="image_4" /></a>
            </div>
        </div>
    </body>
</html>
这样只是能看到你当前程序的里图片移动效果,想实现你的功能得换种思路

[ 本帖最后由 gulimeksoft 于 2010-8-8 23:46 编辑 ]
2010-08-08 22:08
快速回复:为什么不能切换相应的颜色背景
数据加载中...
 
   



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

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