working with time?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bad_Kid

    working with time?

    how to set javascript to start every x ms?? [setTimeout('nam e()', speed)] ??
    - and how to start that same javascript (second instance) with delay - for
    example ->
    javascript colors specified text to red and back to black every x ms...
    how to start that same javascript on another text, with slight delay? (so it
    goes: 1st text goes red, __ , 2nd text goes red, ___ 1st text goes black,
    ___ 2nd text goes black,___ ???



  • Dr John Stockton

    #2
    Re: working with time?

    JRS: In article <cc6op0$h22@oda h37.prod.google .com>, seen in
    news:comp.lang. javascript, ekimnosnews <ekimnosnews@ho tmail.com> posted
    at Sat, 3 Jul 2004 10:01:20 :
    [color=blue]
    >function changeText (id) {
    >var element = document.getEle mentById("text" + id);
    >stuff = false;
    >if (document.all) {
    >if (element.style. color == "rgb(255, 0, 0)") {
    >element.style. color = "#000000";
    >} else {
    >element.style. color = "#FF0000";
    >}
    >} else {[/color]
    [color=blue]
    >if (element.style. color == "#FF0000") {
    >element.style. color = "#000000";
    >} else {
    >element.style. color = "#FF0000";
    >}[/color]

    if those 5 lines work,
    element.style.c olor ^= 0xFF0000
    should work
    [color=blue]
    >}[/color]

    However, since the colour is being changed in a preordained sequence, it
    should be simpler to use
    X %= n ; element.style.c olor = [0x000000, 0xFF0000, ...][X++] ;
    where the literal array has n elements and X is declared outside the
    function changeText. That may well remove the need for feature
    detection.


    Code should be indented to show logical structure - see FAQ/notes.

    --
    © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
    <URL:http://jibbering.com/faq/> JL / RC : FAQ for news:comp.lang. javascript
    <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: working with time?

      Dr John Stockton <spam@merlyn.de mon.co.uk> writes:
      [color=blue]
      > if those 5 lines work,
      > element.style.c olor ^= 0xFF0000
      > should work[/color]

      Unlikely. The value of element.style.c olor is a string.
      You don't know the format returned, althoug it is likely to be
      #xxxxxx. Converted to a number, that is NaN, and xor'in it with
      0xFF0000 will not change that ... and if it did, the result would
      be a number, not a CSS color value.

      /L
      --
      Lasse Reichstein Nielsen - lrn@hotpop.com
      DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
      'Faith without judgement merely degrades the spirit divine.'

      Comment

      Working...