Results 1 to 8 of 8

Thread: variables to hide and unhide divisions

  1. #1
    Join Date
    Aug 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default variables to hide and unhide divisions

    I'd like to use something similar to imageswaps, but to hide and unhide divisions rather than images.
    If I have a div class of ctrtext. I'd like to have several instances with different text, and then use OnMouseOver functions to toggle the visibility:visible or hidden css in order to show the proper text.

    Alternatively, I could have two div classes ctrtext-vis ctrtext-hide and toggle the class assigned to that section of text.

    Is there a way to throw instructions from the onmouseover or a similar function to css properties of a division?

    (or other creative suggestions I didn't think of?)

    View case in point at http://www.dday76.net/home.htm

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Using classes is neater:
    Code:
    <script type="text/javascript">
    window.onload = function() {
      var hideDiv = function(e) {
        if((e && e.target && e.target === this) || (window.event && window.event.srcElement && window.event.srcElement === this))
          this.style.className = "ctrtext-hide";
      };
      var showDiv = function(e) {
        if((e && e.target && e.target === this) || (window.event && window.event.srcElement && window.event.srcElement === this))
          this.style.className = "ctrtext-vis";
      };
      for(var i = 0, e = document.getElementsByTagName("div"); i < e.length; ++i)
        if(e[i].className.indexOf("ctrtext-") !== -1) {
          e[i].onmouseover = showDiv;
          e[i].onmouseout = hideDiv;
        }
    };
    </script>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Aug 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Twey,

    Thanks loads. It looks like this script will show the division if onRollover of something. I'm not sure how to match the division with the link.

    How do I tag div#links to ensure rollovers will only show the div.ctrtext- instance that includes the text related to links?

    I updated the document online to include your suggestions. Can you take me one step further?

    Jason

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Any DIV with a class containing clrtext- will switch to clrtext-vis on mouse over and clrtext-hide on mouse out. It's as simple as that.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Aug 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    That's what I thought... The page lists links to 6 different areas of the website. In the center of the links is a text box welcoming the user. If the user rolls over the link for area #1, the text area in the middle should change to text relating to area #1.

    It looks like the code will change the text if the user rolls over the text rather than the link. Thanks for your patience on this.

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Aha, I see. OK. Try this:
    Code:
    <script type="text/javascript">
      window.onload = function() {
        var showCurrent = function() {
          for(var j = 0, f = document.getElementsByName("description"); j < e.length; ++j)
            if(f[j].className.indexOf(this.text) !== 0) {
              if(f[j].style.display !== "none")
                f[j].style.display = "none";
            } else if(f[j].style.display !== '')
              f[j].style.display = '';
        };
        for(var i = 0, e = document.getElementsByName("desclink"); i < e.length; ++i)
          e[i].onmouseover = showCurrent;
      };
    </script>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Aug 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks. That looks like the right thing.

    1. Just out of curiosity, is there a reason you used display instead of visibility?

    2. What do I stick on the links and the divisions? I'm still not sure how to activate the Js.

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    1. Just out of curiosity, is there a reason you used display instead of visibility?
    Visibility doesn't affect the layout of the page; it simply shows an empty space where the element would be. Since you have several elements all in the same space, using visibility here would cause the last element specified to appear considerably lower down the page than the first element.
    2. What do I stick on the links and the divisions? I'm still not sure how to activate the Js.
    The links need to have a name of "desclink"; the text elements need to have a name of "description" and a class of the link text that refers to them. For example:
    Code:
    <a href="philosophy.html" name="desclink">My Philosophy</a>
    <p name="description" class="My Philosophy">Lorem ipsum dolor sit amet...</p>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

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