| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1300 人关注过本帖
标题:新闻滚动条求助..
只看楼主 加入收藏
fujinliang
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2007-3-30
结帖率:0
收藏
 问题点数:0 回复次数:1 
新闻滚动条求助..
function addLoadListener(fn)
{
    if(typeof window.addEventListener !='undefined')
    {
        window.addEventListener('load',fn,false);
    }
    else if(typeof document.addEventListener !='undefined')
    {
        document.addEventListener('load',fn,false);
    }
    else if(typeof window.attachEvent !='undefined')
    {
        window.attachEvent('onload',fn);
    }
    else
    {
        var old=window.onload;
        if(window.onload !='function')
        {
            window.onload=fn;
        }
        else
        {
            window.onload=function()
            {
                old();
                fn();
            };
        }
    }
}
function attachEventListener(target,eventType,functionRef,capture)  
{
    if(typeof target.addEventListener !="undefined")
    {
        target.addEventListener(eventType,functionRef,capture);
    }
    else if(typeof target.attachEvent !="undefined")
    {
        target.attachEvent("on"+eventType,functionRef);
    }
    else
    {
        var eventType="on"+eventType;
        if(typeof target[eventType] == "function")
        {
            var old=target[eventType];
            target[eventType]=function()
            {
                old();
                return functionRef();
            };
        }
        else
        {
            target[eventType]=functionRef;
        }
    }
}
function retrieveComputedStyle(target,styleProperty)
{
    var elementStyle=null;
    if(typeof target.currentStyle !="undefined")
    {
        elementStyle=target.currentStyle;
    }
    else
    {
        elementStyle=document.defaultView.getComputedStyle(target,null);
    }
    return elementStyle[styleProperty];
}

addLoadListener(initNewTicker);
function initNewTicker()
{
    var newScroller=document.getElementById("newScroller");
    newScroller.style.top=0;
    newScroller.bool=true;
   attachEventListener(newScroller.parentNode,"mouseover",gundong,false);
     attachEventListener(newScroller.parentNode,"mouseout",yikai,false);

    if(retrieveComputedStyle(newScroller,"position") =="relative")
    {
        var parentW=newScroller.offsetHeight;
        newScroller.style.position="absolute";
        newScroller.realwidth=newScroller.offsetHeight;
       if(parentW>newScroller.realwidth)
       {
           newScroller.realwidth=parentW;
       }
       newScroller.style.position="relative";
    }
   else
   {
       newScroller.realwidth=newScroller.clientHeight;
   }
   moveLeft();
   return true;
}
function moveLeft()
{
    var speed=5;
    var newScroller=document.getElementById("newScroller");
    var currentLeft=parseInt(newScroller.style.top);
    if(currentLeft<newScroller.realwidth*-1)
    {
        newScroller.style.top=newScroller.parentNode.offsetHeight+"px";
    }
    else
    {
        newScroller.style.top=(currentLeft-speed)+"px";
    }
    newScroller.targetTime=setTimeout("moveLeft()",100);
    return true;
}
function getEventTarget(event)
{
    var targetElement=null;
    if(typeof event.target !="undefined")
    {
        targetElement=event.target;
    }
    else if(typeof event.srcElement !="undefined")
    {
        targetElement=event.srcElement;
    }
   while(targetElement.nodeType==3 && targetElement.parentNode !=null)
   {
       targetElement=targetElement.parentNode;
   }
   return targetElement;
}
function stopEvent(event)
{
    if(typeof event.stopPropagation !="undefined")
           {
                 event.stopPropagation()
        }
       else{
               cancelBubble=true;
         }
}
function gundong(event)
{
    if(typeof event=="undefined")
    {
        event=window.event
    }
    target=getEventTarget(event);
    while(target.nodeName.toLowerCase() !="div")
    {
        target=target.parentNode;
    }
    
    clearTimeout(document.getElementById("newScroller").targetTime);
    stopEvent(event);
    return true;
}
function yikai(event)
{if(typeof event=="undefined")
    {
        event=window.event
    }
    target=getEventTarget(event);
    while(target.nodeName.toLowerCase() !="div")
    {
        target=target.parentNode;
    }



        if(target.id == "newScroller")
        {
            moveLeft();
            }

        stopEvent(event);
}


HTML代码;
Css:
#newTicker
{
position:relative;
width:300px;
height:35px;
overflow:hidden;
}
#newScroller
{
position:absolute;
position/**/:relative;
height:35px;
line-height:35px;
white-space:nowrap;
}


<body>
<div id=newTicker>
<div id=newScroller>
dddddddddddddddddddddddddfdddddddddddddddd12333322221232dfdfffffdfdfdfdfd
</div>
</div>
</body>
搜索更多相关主题的帖子: window onload else function typeof 
2008-08-18 16:20
fujinliang
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2007-3-30
收藏
得分:0 
麻烦高手看哈mouseover与mouseout事件,,,,怎么鼠标从空白处移到文字上去的时候,,文字还在动啊,,,,是不是因为这两个都加入了</DIV>标签,,,从一个元素移到另一个元素就会触发mouseout事件啊,,,,那怎么样才能使其不触发呢,而只从父元素移开才触发mouseout呢>>>>
2008-08-18 16:23
快速回复:新闻滚动条求助..
数据加载中...
 
   



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

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