On mouse out: How to revert back to background img

Discussion in 'JavaScript' started by kilmurray, Feb 7, 2009.

  1. #1
    Basically I am having a problem with the following:

    <table width="222" border="0" cellpadding="0" cellspacing="0" background="img/subbacklink.gif">
    <tr>
    <td height="24" width="222" valign=middle>&nbsp; <b>Kilmurray
    :</b></td>
    </tr>
    <tr>
    <td width="222" height=3 bgcolor="#ffffff"></td>
    </tr>
    <tr>
    <td height="24" width="222" valign=middle onMouseOver="javascript:taust(this,'#0F363F')"onMouseOut="javascript:taust(this,'#202020')">&nbsp;

    Basically, when the mouse moves off it no longer shows the main tables (img/subbacklink.gif) but the colour #202020. What code do I use so the background image stays visable? Obviously removing the onMouseOut will not work.

    Thanks,
    Paul.
     
    kilmurray, Feb 7, 2009 IP
  2. yoavmatchulsky

    yoavmatchulsky Member

    Messages:
    57
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    48
    #2
    you need to tweak your "taust" function
    paste it in here
    maybe someone can help
     
    yoavmatchulsky, Feb 7, 2009 IP
  3. kilmurray

    kilmurray Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Here is the function (i think, as I am semi-intoxicated).

    function taust(asi1, col1)
    { asi1.bgColor = col1; }

    Cheers.
     
    kilmurray, Feb 7, 2009 IP
  4. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #4
    you can use the background property and apply this like so...

    this.background = col1 + " url(img/subbacklink.gif)";

    or change the inline call to:
    onMouseOut="javascript:taust(this,'#202020 url(img/subbacklink.gif)')
    and the function to:

    this.background = col1;


    on another note, i am not sure if it wont be better to change this via the styles collection instead...
     
    dimitar christoff, Feb 8, 2009 IP
  5. kilmurray

    kilmurray Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    As a complete Java plank, what should the new .js file containing the function look like? I changed a few odds and ends given what you had suggested, but so far it will only change the text colour and not highlight the table as before, which to me is saying the javascript doesn't work now. I just wished I paid more attention at advanced computer science classes instead of infiltrating the college network to spread games!
     
    kilmurray, Feb 8, 2009 IP
  6. darrenbeige

    darrenbeige Peon

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Nowadays, the use of CSS:hover is better, and more widespread amongst browsers.
     
    darrenbeige, Feb 8, 2009 IP
  7. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #7
    alas, no.

    http://reference.sitepoint.com/css/pseudoclass-hover

    no support that can be relied upon pre-ie7. thats still more than a quarter of my IE visitors.

    
    //change the call to add the css for background image in addition to colour.
    ... onMouseOut="javascript:taust(this,'#202020 url(img/subbacklink.gif)')" >&nbsp; 
    
    
    var taust = function(asi1, col1) {
    // updated function to use the css background propertly instead of background-color.
       asi1.background = col1; // can specify all in 1 go, inc colour and image, background repeat and positions.
    };
    
    PHP:
     
    dimitar christoff, Feb 8, 2009 IP
  8. darrenbeige

    darrenbeige Peon

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Fair enough.
     
    darrenbeige, Feb 8, 2009 IP