Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2005
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    img onmouseover/out & a:active ‘if’?

    The problem:
    -the a:active thumbnail loses opacity with onmouseout.

    What works:
    -thumbnail img, that also is a link, is defined with 30% opacity
    -onmouseover changes this to 100% opacity
    -onmouseout returns img to 30% opacity
    -clicking thumbnail calls a jscript for swaping out a target image

    What’s needed:
    -set the thumbnail img to 100% opacity when it has been clicked (a:active) AND retain that opacity until a different thumbnail img is clicked.
    -other thumbnails will continue to change opacity settings with onmouseover & -out.

    I don’t know scripting and therefore don’t know how to write a script for this. TIA!

    Here’s what I have thus far.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    
    <style type="text/css">
    <!--
    img.transON  {opacity: 0.3; -moz-opacity: 0.3; filter: alpha(opacity=30);}
    img.transOFF {opacity: 1; -moz-opacity: 1; filter: alpha(opacity=100);}
    -->
    </style>
    
    <script type="text/javascript">
    <!--
    function MM_swapImgRestore() { //v3.0
      var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
    }
    
    function MM_preloadImages() { //v3.0
      var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }
    
    function MM_findObj(n, d) { //v3.0
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
    }
    
    function MM_swapImage() { //v3.0
      var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
       if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
    }
    -->
    </script>
    
    </head>
    <body>
    <div>
    
    <div>
    <a href="#"><img alt="" src="thumbs/thumb01.gif" class="transON"
       onmousedown="MM_swapImage('target','','images/image01.jpg',1)"
       onmouseover="this.className='transOFF'" 
       onmouseout="this.className='transON'" /></a>
    
    <a href="#"><img alt="" src="thumbs/thumb02.gif" class="transON"
      onmousedown="MM_swapImage('target','','images/image02.jpg',1)"
      onmouseover="this.className='transOFF'" 
      onmouseout="this.className='transON'" /></a>
    </div>
    
    <div>
      <img src="images/image01.jpg" alt="" id="target" />
    </div>
    
    </div>
    </body>
    </html>

  • #2
    New Coder
    Join Date
    Jul 2005
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No one has any ideas?

  • #3
    New Coder
    Join Date
    Jul 2005
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It turned out to be a very simple change in CSS.

    #thumbsInner a img {opacity: 0.3; -moz-opacity: 0.3; filter: alpha(opacity=30);}
    #thumbsInner a:hover img {opacity: 1; -moz-opacity: 1; filter: alpha(opacity=100);}
    #thumbsInner a:active img, #thumbsInner a:focus img {opacity: 1; -moz-opacity: 1; filter: alpha(opacity=100);}

    <a href="#"><img alt="" src="thumbs/thumb01.gif" onmousedown="MM_swapImage('target','','images/image01.jpg',1)" width="36" height="36" /></a>

    The problem being, however, that the first thumbnail is not highlighted on page load, and that the thumbnail loses focus (and thus 100% opacity) when the user clicks anywhere else on the page.


  •  

    Posting Permissions

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