"complex" rollover animation question

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

    "complex" rollover animation question

    I'm relatively new to scripting in JavaScript, so I'm not too
    surprised I'm having difficulty scripting up an animation effect for
    my personal site.

    What I'm trying to do is the following: When I go onMouseOver on a
    button in a nav bar, I want that button to switch to a different image
    while at the same time another blank image changes as an animation to
    an associated image. When I go onMouseOut, the bar image reverts back
    to the original and the blank area image steps back through the
    animation to the original, blank image.

    I can get this to work for a single nav bar button, but when I attempt
    to generalize the functions to work for the second nav bar button (and
    a second, different animation that occurs in the same blank area), it
    fails.

    I can get the second nav button to work correctly on rollover by
    splitting the simple rollover function out from the animation
    function, but I cannot get the second animation to work regardless.

    Any suggestions on how I might solve this problem? I can post code if
    necessary.

    Thanks a lot.

    Brian
  • DU

    #2
    Re: "complex&q uot; rollover animation question

    Brian Angliss wrote:
    [color=blue]
    > I'm relatively new to scripting in JavaScript, so I'm not too
    > surprised I'm having difficulty scripting up an animation effect for
    > my personal site.
    >
    > What I'm trying to do is the following: When I go onMouseOver on a
    > button in a nav bar, I want that button to switch to a different image
    > while at the same time another blank image changes as an animation to
    > an associated image. When I go onMouseOut, the bar image reverts back
    > to the original and the blank area image steps back through the
    > animation to the original, blank image.
    >
    > I can get this to work for a single nav bar button, but when I attempt
    > to generalize the functions to work for the second nav bar button (and
    > a second, different animation that occurs in the same blank area), it
    > fails.
    >
    > I can get the second nav button to work correctly on rollover by
    > splitting the simple rollover function out from the animation
    > function, but I cannot get the second animation to work regardless.
    >
    > Any suggestions on how I might solve this problem? I can post code if
    > necessary.
    >
    > Thanks a lot.
    >
    > Brian[/color]

    I know it's possible (even easy) to do rollover effects on 2 groups of
    objects.

    Without being able to see any code out of your post and no url, it's
    extremely difficult to suggest anything concrete (furthermore if your
    code is complex according to you)... just general not-too-commital
    guesswork. Is your webpage markup syntax valid, validated?

    DU
    --
    Javascript and Browser bugs:

    - Resources, help and tips for Netscape 7.x users and Composer
    - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x


    Comment

    • Brian Angliss

      #3
      Re: "complex&q uot; rollover animation question

      On Thu, 11 Sep 2003 01:07:58 -0400, DU <drunclear@hotR EMOVEmail.com>
      wrote:
      [color=blue]
      >I know it's possible (even easy) to do rollover effects on 2 groups of
      >objects.
      >
      >Without being able to see any code out of your post and no url, it's
      >extremely difficult to suggest anything concrete (furthermore if your
      >code is complex according to you)... just general not-too-commital
      >guesswork. Is your webpage markup syntax valid, validated?
      >
      >DU[/color]

      The following is how I'm pre-loading the animation images:

      if (document.image s) {
      bltv=new Array();
      bltv[0]="images/blogtv6.jpg";
      bltv[1]="images/blogtv5.jpg";
      bltv[2]="images/blogtv4.jpg";
      bltv[3]="images/blogtv3.jpg";
      bltv[4]="images/blogtv2.jpg";
      bltv[5]="images/blogtv1.jpg";
      bltv[6]="images/base_tv.jpg";

      blogtv = new Array();
      for (var i=0;i<bltv.leng th;i++){
      blogtv[i] = new Image();
      blogtv[i].src = bltv[i];
      }
      }

      and

      if (document.image s) {
      dytv=new Array();
      dytv[0]="images/daytv6.jpg";
      dytv[1]="images/daytv5.jpg";
      dytv[2]="images/daytv4.jpg";
      dytv[3]="images/daytv3.jpg";
      dytv[4]="images/daytv2.jpg";
      dytv[5]="images/daytv1.jpg";
      dytv[6]="images/base_tv.jpg";

      daytv = new Array();
      for (var j=0;j<dytv.leng th;j++){
      daytv[j] = new Image();
      daytv[j].src = daytv[j];
      }
      }

      The simple rollover function works just fine, but I can't get the two
      animations to work properly. The code below is what i'm trying to get
      working:

      // blog
      function aniOnb(imgName) {
      clearTimeout(co unter);
      if (document.image s) {
      i--;
      animOnb=eval("b logtv["+i+"].src");
      document.tv.src =animOnb;
      counter=setTime out("aniOnb()", 75);
      if (i==0) clearTimeout(co unter);
      }
      }

      function aniOffb(imgName ) {
      clearTimeout(co unter);
      if (document.image s) {
      i++;
      animOffb=eval(" blogtv["+i+"].src");
      document.tv.src =animOffb;
      counter=setTime out("aniOffb()" ,75);
      if (i==6) clearTimeout(co unter);
      }
      }

      // dailies
      function aniOnd(imgName) {
      clearTimeout(co unter);
      if (document.image s) {
      j--;
      animOnd=eval("d aytv["+j+"].src");
      document.tv.src =animOnd;
      counter=setTime out("aniOnd()", 75);
      if (j==0) clearTimeout(co unter);
      }
      }

      function aniOffd(imgName ) {
      clearTimeout(co unter);
      if (document.image s) {
      j++;
      animOffd=eval(" daytv["+j+"].src");
      document.tv.src =animOffd;
      counter=setTime out("aniOffd()" ,75);
      if (j==6) clearTimeout(co unter);
      }
      }

      And I'm calling the functions using the two following test lines of
      markup:

      <a href="a.htm" onMouseOver="bu tOn('but1');ani Onb();return true;"
      onMouseOut="but Off('but1');ani Offb();return true;"><img
      src="images/blog.jpg" width="135" height="40" name="but1"
      border="0"></a>

      <a href="a.htm" onMouseOver="bu tOn('but2');ani Ond();return true;"
      onMouseOut="but Off('but2');ani Offd();return true;"><img
      src="images/daily.jpg" width="135" height="40" name="but2"
      border="0"></a>


      I had originally tried to get things working with a single animation
      function and found that I couldn't get it to work right. That code is
      below:

      function aniOn(imgName, animName) {
      clearTimeout(co unter);
      if (document.image s) {
      i--;
      animOn=eval(ani mName+"["+i+"].src");
      document.tv.src =animOn;
      counter=setTime out("aniOn()",7 5);
      if (i==0) clearTimeout(co unter);
      img_on=eval(img Name+"_on.src") ;
      document [imgName].src=img_on;
      }
      }

      function aniOff(imgName, animName) {
      clearTimeout(co unter);
      if (document.image s) {
      i++;
      animOff=eval(an imName+"["+i+"].src");
      document.tv.src =animOff;
      counter=setTime out("aniOff()", 75);
      if (i==6) clearTimeout(co unter);
      img_off=eval(im gName+"_off.src ");
      document [imgName].src=img_off;
      }
      }

      I could get it working before I generalized
      eval("name["+i+"].src")
      to
      eval(animName+"["+i+"].src")

      It freaked out and started misbehaving in all sorts of ways. So now
      I'm trying a brute-force approach with multiple functions.

      I realized last night that if I move the mouse from button1 to
      button2, the first animation doesn't complete and the animation hangs
      at the step when I went over button2. I'll need to fix that too, but
      I want to get the multiple animations working first. One thing at a
      time.

      Brian

      Comment

      • asdf asdf

        #4
        Re: &quot;complex&q uot; rollover animation question

        Hello, here is something that I threw together (hence its crappiness)
        that I think demonstrates some of the things you are trying to do:


        <script>
        function howdy() {
        var obj = event.srcElemen t;
        if (!obj.magic) return;
        window.setTimeo ut("doit('"+obj .id+"',5,"+(++o bj.magic)+")",1 );
        }
        function unhowdy() {
        var obj = event.srcElemen t;
        if (!obj.magic) return;
        window.setTimeo ut("doit('"+obj .id+"',-5,"+(++obj.magi c)+")",1);
        }
        function doit(objid,dx,m agicnum) {
        var obj = document.getEle mentById(objid) ;
        if (!obj || magicnum!=obj.m agic) return;
        if (!obj.val) obj.val = 0;
        obj.val += dx;
        if (obj.val < 0) {
        obj.val = null;
        obj.style.filte r=null;
        } else if (obj.val<50) {
        obj.style.filte r="progid:DXIma geTransform.Mic rosoft.MotionBl ur(strength="+o bj.val+")";
        window.setTimeo ut("doit('"+obj id+"',"+dx+","+ magicnum+")",10 );
        }
        }
        </script>
        <body onmouseover="ho wdy()" onmouseout="unh owdy()">
        <img magic=1 id=but1 src="http://www.google.com/images/logo.gif"><br>
        <img magic=1 id=but2 src="http://www.google.com/images/logo.gif"><br>
        <img magic=1 id=but3 src="http://www.google.com/images/logo.gif"><br>
        <img magic=1 id=but4 src="http://www.google.com/images/logo.gif"><br>
        <img magic=1 id=but5 src="http://www.google.com/images/logo.gif"><br>
        <img magic=1 id=but6 src="http://www.google.com/images/logo.gif"><br>
        </body>

        Comment

        • Brian Angliss

          #5
          Re: &quot;complex&q uot; rollover animation question

          Thanks a lot for the suggested code. I'll give it a shot and see if I
          can make it work.

          Brian

          On 11 Sep 2003 17:54:17 -0700, b0b0b0b@yahoo.c om (asdf asdf) wrote:
          [color=blue]
          >Hello, here is something that I threw together (hence its crappiness)
          >that I think demonstrates some of the things you are trying to do:[/color]

          Comment

          • Brian Angliss

            #6
            setTimeout problem; was Re: &quot;complex&q uot; rollover animation question

            I'm trying to get your example working, and I'm getting errors on the
            setTimeout of howdy()

            On 11 Sep 2003 17:54:17 -0700, b0b0b0b@yahoo.c om (asdf asdf) wrote:
            [color=blue]
            > window.setTimeo ut("doit('"+obj .id+"',5,"+(++o bj.magic)+")",1 );[/color]

            Basically, the JS Console in Navigator 7.0x says that the above
            statement is "missing a ')' after the argument list" I don't see
            where - any suggestions why it's freaking out?

            Thanks for your help.

            Brian

            Comment

            Working...