CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2008
    Posts
    5

    Resolved [RESOLVED] JavaScript: making text appear onmouseover a different rect element

    Hey all,

    Is anyone able to tell me how I set a text to animate from hidden to visible when I mouseover a different ‘rect’ element not containing this text? The text and the associated animation are in one function, and the ‘rect’ element is created from a generic rect-creating function and then called in another main-box function.

    Currently, the animation code looks like this:

    Code:
    var anim = SVGDoc.createElementNS('http://www.w3.org/2000/svg', 'animate');
    
    anim.setAttributeNS(null,'attributeName',"visibility");
    
    anim.setAttributeNS(null,'begin', "0s");
    
    anim.setAttributeNS(null,'dur',"1s");
    
    anim.setAttributeNS(null,'fill',"freeze");
    
    anim.setAttributeNS(null,'from', "hidden");
    
    anim.setAttributeNS(null,'to', "visible");
    
    infoText.appendChild(anim);
    Obviously I need to change the ‘begin’ attribute and add an ‘end’ attribute, but I don’t know to what… I’m guessing that getElementById will help, and I’ve tried several different ways of implementing this and the associated variable, but to no avail. Can anyone help me please?

    Thank you.
    Last edited by jktjktjkt; August 18th, 2008 at 07:15 AM. Reason: [RESOLVED]

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: [RESOLVED] JavaScript: making text appear onmouseover a different rect element

    Why don't you just change the CSS display style?

    Code:
    function toggleElement(id) { // pass id parameter as the element id
      theElement = document.getElementById(id);
      theElement.style.display = (theElement.style.display == '') ? 'block' : '';
    }
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jul 2005
    Location
    Currently in Mexico City
    Posts
    568

    Re: JavaScript: making text appear onmouseover a different rect element

    For the current case - as PeejAvery said.

    Additionally for the future, for the cases when you need to change css of the same element you put mouse over.

    In your attached CSS:
    Code:
    body {behavior:url(styles/csshover2.htc);}
    /*
    csshover2.htc is an IE hack file that makes IE6 understand "hover" css property
    for all elements (originally IE6 has "hover" for <a> only);
    csshover2.htc path should be set relatively to your html, not this css file;
    it can be downloaded from here for ex.: http://www.xs4all.nl/~peterned/htc/csshover2.htc
    */
    .class1 {color:#FF0000; border:1px solid #666666;}
    .class1:hover {color:#FFFF00; border:1px solid #FFFFFF;}
    It's that simple you just define the style for normal appearance, and the appearance when hover is on. If you attached csshover2.htc correctly this should work for any element in any browser. Some pretty nice buttons annimation can be made using this approach for ex. And with no need of javascript.
    Wanna install linux on a vacuum cleaner. Could anyone tell me which distro sucks better?

    I had a nightmare last night. I was dreaming that I’m 64-bit and my blanket is 32-bit and I couldn’t cover myself with it, so I’ve spent the whole night freezing. And in the morning I find that my blanket just had fallen off the bed. =S (from: bash.org.ru)

    //always looking for job opportunities in AU/NZ/US/CA/Europe :P
    willCodeForFood(Arrays.asList("Java","PHP","C++","bash","Assembler","XML","XHTML","CSS","JS","PL/SQL"));

    USE [code] TAGS! Read this FAQ if you are new here. If this post was helpful, please rate it!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured