给你个例子 15秒<script>
/*  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            DHTML ScreenSaver    Author  : Darren Neimke
    Source  : http://www.showusyourcode.com/
    Email   : [email protected]
    Date    : 28-Aug-2002
    
    Version 1.0.1
    
    Comments:
    There's still quite a few *magic* numbers in 
    here as I'm struggling to come to terms with 
    measuring the Screen innerWidth and innerHeight
    values in IE.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */var is_ie5_5up = ( true )// -------------------------------------------------------------------// -------------------------------------------
//        Global variables
// -------------------------------------------var gIntrvlSSRepaint ;  // the timer for repainting
var gIntrvlSSListen ;   // keep checking to see if time has elapsed and required to start the SS
var gIntrvlSSElapsed ;  // since last activity
var counter = 0 ;       // MAGIC?var gWidth, gHeight ;   // store the screen dimensionsvar LINE_WIDTH                  = 90 ;
var ACTIVITY_TIMEOUT            = 15000 ;  // 15 seconds
var CHECK_ACTIVITY_INTERVAL     = 1000 ;   // 1 second
var REPAINT_INTERVAL    = 100 ;
var SCROLLBAR_WIDTH     = 0
var TASKBAR_HEIGHT      = 0// If you already do stuff in a onload event handler, then you must
// call gfnSSInitialize() from there, otherwise just leave this code
// as-is and it will call itself
var gobjScreenSaver ;function screenSaverInit()
{
    if (is_ie5_5up)
    {
        new ScreenSaver() ;
        gobjScreenSaver.Init() ;
        CalcScreenAvail()
        gIntrvlSSElapsed = new Date().valueOf() ;
        gIntrvlSSListen = setInterval( "activityChecker()", CHECK_ACTIVITY_INTERVAL ) ;
    }
}// If you need to do stuff in these handlers as well, just add
// you own stuff in, but be sure to still call the ScreenSaver helpers.
window.onload = function() { screenSaverInit() ; }    // Instantiate the ScreenSaver
document.onkeypress = function() { activityMonitor() ; }
document.onmousemove = function() { activityMonitor(); }
document.onmousedown = function() { activityMonitor() ; }
document.onmouseup = function() { activityMonitor() ; }
window.onresize = function() { CalcScreenAvail() ; }// -------------------------------------------
//        Helper functions etc.
// -------------------------------------------// used from several sections
function CalcScreenAvail()
{
    gWidth = document.body.clientWidth;
    gHeight = document.body.clientHeight;
    if(!(typeof(gobjScreenSaver) == 'undefined'))
    {
        try
        {
            gobjScreenSaver.SetScreenSize()
        }
        catch(e){
            // possibly route to an exception handler
        }
    }
}// Event Listener - called on a keypress and mousemove
function activityMonitor()
{
    if(!(typeof(gobjScreenSaver) == 'undefined'))
    {
        try
        {
gIntrvlSSElapsed = new Date().valueOf()
            if(gobjScreenSaver.IsActive && !(gobjScreenSaver.IsPreview))
                gobjScreenSaver.Stop() ;
}
        catch(e){
            // possibly route to an exception handler
        }
    }
}// called on a timer to invoke (Start) the screensaver
function activityChecker()
{
    var tmp = new Date().valueOf()
    if(((tmp - gIntrvlSSElapsed) > ACTIVITY_TIMEOUT) && !(gobjScreenSaver.IsActive))
    {
        gobjScreenSaver.Start()
    }
}// -------------------------------------------------------------------document.writeln('<style>');
document.writeln('#myLine')
document.writeln('{')
document.writeln('position:    absolute ;')
document.writeln('top:         100px ;')
document.writeln('left:        200px ;')
document.writeln('width:       100px ;')
document.writeln('height:      2px ;')
document.writeln('line-height: 2px ;')
document.writeln('overflow:    hidden ;')
document.writeln('z-index:     3099 ;')
document.writeln('}')
document.writeln('#myScreensaver')
document.writeln('{')
document.writeln('position:    absolute ;')
document.writeln('top:         0px ;')
document.writeln('left:        0px ;')
document.writeln('z-index:     90 ;')
document.writeln('}')
document.writeln('<\/style>')
document.writeln('<DIV Id="myScreensaver"></DIV>') ;// -------------------------------------------
//        Line and Screensaver Classes
// -------------------------------------------function Line(obj, xpos, ypos)
{
    this.Started = 0
    this.Element = obj
    this.xpos = xpos
    this.ypos = ypos
    this.decreaseX = true
    this.decreaseY = true   
    
    this.Reset = function()
    {
        this.Started = 0
        this.xpos = 200
        this.ypos = 100
        this.Element.style.display = 'none'
        this.decreaseX = true
        this.decreaseY = true    
    }
}

解决方案 »

  1.   


    function ScreenSaver()
    {
        gobjScreenSaver = this
        var oarrShapes  = new Array() ; // the array of Shape Objects
        this.IsActive   = false ; // When the screensaver is on
        this.IsPreview    = false ; // IsPreview is a small buffer that allows users to view the screensaver from a button click (or whatever)
        
        // Color stuff
        this.COLOR_BASE = 0
        this.MAX_ITEMS  = 60
        this.INCR       = (255 / parseInt(this.MAX_ITEMS / 3))
        // Create the Color Enumerated Type
        this.Color          = new Array() ;
        this.Color.Red      = this.COLOR_BASE ;
        this.Color.Green    = this.COLOR_BASE ;
        this.Color.Blue     = this.COLOR_BASE ;
        
        this.Init = function ()
        {
            var curLine ;
            var bg = document.getElementById("myScreensaver")
            bg.style.backgroundColor = "Black" ;
            bg.style.position = "absolute"
            bg.style.display = "none"
            this.Bg = bg
            // Generate the initial oarrShapes
            for (var i=0; i<=this.MAX_ITEMS; i++)
            {
                // initialize the oarrShapes
                this.UpdateColorValues(i)
                curLine = document.createElement("DIV")
                with(curLine) {
                    id = "myLine"
                    style.backgroundColor = "rgb(" + this.Color.Red + "," + this.Color.Green + "," + this.Color.Blue + ")" //colors[i] ;
                    style.zIndex = 201 - i ;
                    style.display = "none"
                }
                document.body.appendChild( curLine )
                curLine.style.pixelWidth = LINE_WIDTH
                oarrShapes[i] = new Line(curLine, 200, 100)
            }
        }
        
        // called on init and onresize to ensure that canvass size matches 
        // screen size
        this.SetScreenSize = function()
        {
            this.Bg.style.height = ( gHeight - TASKBAR_HEIGHT ) ;
            this.Bg.style.width = ( gWidth - SCROLLBAR_WIDTH ) ;
        }
        
        
        this.Start = function( isPreviewMode )
        {
            // if the user has specified IsPreviewMode set a delay
            if( isPreviewMode ) this.IsPreview = true ;
    this.Bg.style.display = ""
            for (var i=0; i<=oarrShapes.length-1; i++)
                oarrShapes[i].Element.style.display = ""    
            this.IsActive = true ;
            startCounter("gobjScreenSaver.Animate()",REPAINT_INTERVAL) ;
        }
        
        this.Stop = function()
        {
    stopCounter(gIntrvlSSRepaint) ;
            this.Bg.style.display = "none"
            for (var i=0; i<=oarrShapes.length-1; i++)
                oarrShapes[i].Reset()
            this.IsActive = false ;
            counter = 0 ;
        }
        
        // helper function used to cycle though the Red/Green/Blue colors
        this.UpdateColorValues = function(counter)
        {
            this.Color.Red = this.COLOR_BASE
            this.Color.Green = this.COLOR_BASE
            this.Color.Blue = this.COLOR_BASE
            if (counter <= parseInt(this.MAX_ITEMS / 3))
            {
                this.Color.Red = 255 - 
                    (parseInt(counter % parseInt(this.MAX_ITEMS / 3)) * this.INCR) 
            }
            else if (counter <= parseInt(parseInt(this.MAX_ITEMS / 3) * 2))
            {
                this.Color.Green = 0 + 
                    (parseInt(counter % parseInt(this.MAX_ITEMS / 3)) * this.INCR)
            }
            else
            {
                this.Color.Blue = 255 - 
                    (parseInt(counter % parseInt(this.MAX_ITEMS / 3)) * this.INCR)
            }
        }
        
        /*  Animate enumerates the oarrShapes collection and sequentially 
        toggles their xpos/ypos position on the screen */
    this.Animate = function()
    {
        var curLine ;
    var bContinue = true ;
    for (var i=0; i<=oarrShapes.length-1; i++)
    {
    curLine = oarrShapes[i]
    // stagger the line starting process...
    if( curLine.Started == 0 ) { curLine.Started = 1; bContinue = false ; }
    curLine.Element.style.left = curLine.xpos ;
    curLine.Element.style.top = curLine.ypos ;
    // If we are near the boundaries then we 
    // need to toggle a switch so that the counter goes in the
    // reverse direction ...
    if(curLine.xpos < 10) curLine.decreaseX = false ;
    if(curLine.xpos > ( gWidth - ( SCROLLBAR_WIDTH + 20 ) ) - LINE_WIDTH ) curLine.decreaseX = true ;
    if(curLine.ypos < 20) curLine.decreaseY = false ;
    if(curLine.ypos > ( gHeight - ( TASKBAR_HEIGHT + 20 ) ) ) curLine.decreaseY = true ;           

    // Now apply the actual counter increment/decrement ...
    if(curLine.decreaseX) {
    curLine.xpos = curLine.xpos - 20 ;
    } else {
    curLine.xpos = curLine.xpos + 20 ;
    }
    if(curLine.decreaseY) {
    curLine.ypos = curLine.ypos - 13 ;
    } else {
    curLine.ypos = curLine.ypos + 13 ;
    }
    // we stagger the line starting process
    if(!(bContinue)) break ;
    }
    // explicitly set this to false, by the time we get to here
    // the required delay has passed
    this.IsPreview = false ;
    }
    }function startCounter(fn,interval)
    {
        gIntrvlSSRepaint = window.setInterval(fn,interval) ;
    }function stopCounter(timer)
    {
        window.clearInterval(timer) ;
    }
    </script>
    <INPUT id="startButton" type="button" value="Start ScreenSaver" name="startButton" onclick="gobjScreenSaver.Start(true) ;">
      

  2.   

    function ClearTimer()
    {
    if(sobjTimer)
    {
    window.clearInterval(sobjTimer);
    }
    //这里调用屏报
    sobjTimer = setInterval("ShowDiv()",30000);}
    </script>
    <BODY onmousemove="ClearTimer()" onload="ClearTimer()" onmouseout="ClearTimer()">
      

  3.   

    我这样做了,也不对。不知道怎么修改他的代码。
    还请net_lover(孟子E章)指教。
    谢谢!!!