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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Image onmouseover change HELP

    Hi everyone. Can anyone help me , i need to make a onmouseover function ,
    when u go with mouse on the left small image it automatically opens the large image in the right, can anyone help me with this ???

  • #2
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,755
    Thanks
    41
    Thanked 191 Times in 190 Posts
    something like....
    Code:
    <script type="text/javascript">
    function expand()
    {
    document.getElementById("Right_Image").style.height="300px";
    document.getElementById("Right_Image").style.width="300px";
    }
    function shrink()
    {
    document.getElementById("Right_Image").style.height="100px";
    document.getElementById("Right_Image").style.width="100px";
    }
    </script>
    .......
    
    <img src="./myimgpath.jpg" alt="myimg" id="Left_Image" onmouseover="expand" 
          onmouseout="shrink" />
    <img src="./myotherimg.jpg" alt="my2ndimg" id="Right_Image" />
    Note:That code needs some work and tidy-ing up (most likely... I doubt i rattled it off absolutely correct ;p)

    Edit:....
    I can't beleive I went right for the javascript... :hover can be used as well

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #3
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Does not work . Thanks for your try to help.

    Maybe u can help me better if u see the image below :
    Attached Thumbnails Attached Thumbnails Image onmouseover change HELP-greytemp-index.jpg  

  • #4
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,518
    Thanks
    3
    Thanked 506 Times in 493 Posts
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <style type="text/css">
    /*<![CDATA[*/
    
    .img {
     width:100px;height:75px;
    }
    
    /*]]>*/
    </style>
    
    <script type="text/javascript">
    // Animate (24-June-2011)
    // by Vic Phillips http://www.vicsjavascripts.org.uk
    
    // To progressively change the Left, Top, Width, Height or Opacity of an element over a specified period of time.
    // With the ability to scale the effect time on specified minimum/maximum values
    // and with three types of progression 'sin' and 'cos' and liner.
    
    // The functional code size is 1.39K
    
    // **** Application Notes
    
    // **** The HTML Code
    //
    // when moving an element the inline or class rule style position of the element should be assigned as
    // 'position:relative;' or 'position:absolute;'
    //
    // The element would normally be assigned a unique ID name.
    //
    
    // **** Initialising the Script.
    //
    // The script is initialised by assigning an instance of the script to a variable.
    // e.g A = new zxcAnimate('left','id1')
    // where:
    //  A           = a global variable                                                               (variable)
    //  parameter 0 = the mode(see Note 1).                                                           (string)
    //  parameter 1 = the unique ID name or element object.                                           (string or element object)
    //  parameter 2 = the initial value.                                                              (digits, default = 0)
    
    // **** Executing the Effect
    //
    // The effect is executed by an event call to function 'A.animate(10,800 ,5000,[10,800]);'
    // where:
    //  A           = the global referencing the script instance.                                 (variable)
    //  parameter 0 = the start value.                                                            (digits, for opacity minimum 0, maximum 100)
    //  parameter 1 = the finish value.                                                           (digits, for opacity minimum 0, maximum 100)
    //  parameter 2 =  period of time between the start and finish of the effect in milliseconds. (digits or defaults to previous or 0(on first call) milliSeconds)
    //  parameter 3 = (optional) to scale the effect time on a specified minimum/maximum.         (array, see Note 3)
    //                 field 0 the minimum value. (digits)
    //                 field 1 the maximum value. (digits)
    //  parameter 3 = (optional) the type of progression, 'sin', 'cos' or 'liner'.                (string, default = 'liner')
    //                 'sin' progression starts fast and ends slow.
    //                 'cos' progression starts slow and ends fast.
    //
    //  Note 1:  Examples modes: 'left', 'top', 'width', 'height', 'opacity.
    //  Note 2:  The default units(excepting opacity) are 'px'.
    //           For hyphenated modes, the first character after the hyphen must be upper case, all others lower case.
    //  Note 3:  The scale is of particular use when re-calling the effect
    //           in mid progression to retain an constant rate of progression.
    //  Note 4:  The current effect value is recorded in A.data[0].
    //  Note 5:  A function may be called on completion of the effect by assigning the function
    //           to the animator intance property .Complete.
    //           e.g. [instance].Complete=function(){ alert(this.data[0]); };
    //
    
    
    
    // **** Functional Code - NO NEED to Change
    
    function zxcAnimate(mde,obj,srt){
     this.to=null;
     this.obj=typeof(obj)=='object'?obj:document.getElementById(obj);
     this.mde=mde.replace(/\W/g,'');
     this.data=[srt||0];
     return this;
    }
    
    zxcAnimate.prototype={
    
     animate:function(srt,fin,ms,scale,c){
      clearTimeout(this.to);
      this.time=ms||this.time||0;
      this.data=[srt,srt,fin];
      this.mS=this.time*(!scale?1:Math.abs((fin-srt)/(scale[1]-scale[0])));
      this.c=typeof(c)=='string'?c.charAt(0).toLowerCase():this.c?this.c:'';
      this.inc=Math.PI/(2*this.mS);
      this.srttime=new Date().getTime();
      this.cng();
     },
    
     cng:function(){
      var oop=this,ms=new Date().getTime()-this.srttime,s=this.data[1],f=this.data[2],d=Math.floor(this.c=='s'?(f-s)*Math.sin(this.inc*ms)+s:this.c=='c'?f-(f-s)*Math.cos(this.inc*ms):(f-s)/this.mS*ms+s);
      d=Math.max(d,s<0||f<0?d:0);
      this.data[0]=d;
      this.apply();
      if (ms<this.mS){
       this.to=setTimeout(function(){oop.cng(); },10);
      }
      else {
       this.data[0]=this.data[2];
       this.apply();
       if (this.Complete) this.Complete(this);
      }
     },
    
     apply:function(){
      if (isFinite(this.data[0])){
       if (this.mde!='opacity') this.obj.style[this.mde]=this.data[0]+'px';
       else zxcOpacity(this.obj,this.data[0]);
      }
     }
    
    }
    
    function zxcOpacity(obj,opc){
     obj.style.filter='alpha(opacity='+opc+')';
     obj.style.opacity=obj.style.MozOpacity=obj.style.WebkitOpacity=obj.style.KhtmlOpacity=opc/100-.001;
    }
    
    </script>
    
    <script type="text/javascript">
    /*<![CDATA[*/
    
    function zxcExpand(o){
     var reg=new RegExp('\\b'+'zxcExpand'+'\\b'),els=document.getElementsByTagName('*'),ary=[],z0=0,oo,split,i,s,z1=0,z1a;
     for (;z0<els.length;z0++){
      if(reg.test(els[z0].className)){
       ary.push(els[z0]);
      }
     }
     for (;z1<ary.length;z1++){
      split=ary[z1].className.split(/\s/);
      oo={};
      for (z1a=0;z1a<split.length;z1a++){
       i=split[z1a].indexOf(':');
       if (i>1){
        oo[split[z1a].substring(0,i).toLowerCase()]=split[z1a].substring(i+1);
       }
      }
      new zxcExpandOOP(ary[z1],oo);
     }
    
    }
    
    function zxcExpandOOP(img,oo){
     var src=oo.src,src=typeof(src)=='string'?src:img.src,obj=new Image();
     obj.src=src;
     this.load(obj,img,oo);
    }
    
    zxcExpandOOP.prototype={
    
     expand:function(ud){
      var pos=this.pos(this.img),oop=this,up=oop.width.data[0],ms=oop.ms;
      if ((ud&&up==0)||(!ud&&up==oop.objw[1])){
       oop.pop.style.visibility='visible';
       oop.pop.style.zIndex=(this.z+(ud?1:0))+'';
       oop.left.animate(pos[0]+oop.xos[ud?1:0],pos[0]+oop.xos[ud?0:1],ms);
       oop.top.animate(pos[1]+oop.yos[ud?1:0],pos[1]+oop.yos[ud?0:1],ms);
       oop.width.animate(oop.objw[ud?0:1],oop.objw[ud?1:0],ms);
       oop.height.animate(oop.objh[ud?0:1],oop.objh[ud?1:0],ms);
      }
     },
    
     init:function(obj,img,oo){
      var oop=this,pop=document.createElement('IMG'),ms=parseInt(oo.duration),xos=parseInt(oo.xoffset),yos=parseInt(oo.yoffset),z=parseInt(oo.zindex);
      pop.src=obj.src;
      pop.style.position='absolute';
      pop.style.visibility='hidden';
      document.body.appendChild(pop);
      this.objw=[img.width,obj.width];
      this.objh=[img.height,obj.height];
      this.xos=[isFinite(xos)?xos:img.width+5,0];
      this.yos=[isFinite(yos)?yos:0,0];
      this.img=img;
      this.pop=pop;
      this.left=new zxcAnimate('left',pop);
      this.top=new zxcAnimate('top',pop);
      this.width=new zxcAnimate('width',pop,0);
      this.width.Complete=function(){
       if (this.data[0]==oop.objw[0]){
        this.obj.style.visibility='hidden';
        this.data[0]=0;
       }
      }
      this.height=new zxcAnimate('height',pop);
      this.ms=isFinite(ms)?ms:1000;
      this.z=(isFinite(z)?z:101);
      img.onmouseover=function(){ oop.expand(true); }
      img.onmouseout=function(){ oop.expand(false); }
     },
    
     pos:function(obj){
      var rtn=[0,0];
      while(obj){
       rtn[0]+=obj.offsetLeft;
       rtn[1]+=obj.offsetTop;
       obj=obj.offsetParent;
      }
      return rtn;
     },
    
     load:function(obj,img,oo){
      if (obj.width>40){
       this.init(obj,img,oo);
      }
      else {
       var oop=this;
       setTimeout(function(){ oop.load(obj,img,oo); },100);
      }
     }
    
    
    
    }
    
    /*]]>*/
    </script>
    <script type="text/javascript">
    /*<![CDATA[*/
    
    function Init(){
    // The expandable images class name must include zxcExpand
    // Options defined in the class name
     // SRC:      = (optional) the scr of the pop up image.                        (string, default = the src of the mouseover image)
     // Duration: = (optional) the duration of the expand effect in milli seconds. (number, default = 1000)
     // XOffset:  = (optional) the X offset from the the mouseover image.          (number, default = left of the mouseover image)
     // XOffset:  = (optional) the Y offset from the the mouseover image.          (number, default = level with the mouseover image)
     // ZIndex:   = (optional) the z-Index of the popup image.                     (number, default = 101)
      zxcExpand();
    }
    
    if (window.addEventListener){
     window.addEventListener('load',Init, false);
    }
    else if (window.attachEvent){
     window.attachEvent('onload',Init);
    }
    
    /*]]>*/
    </script>
    </head>
    
    <body>  http://www.codingforums.com/showthread.php?t=238662
    <img class="img zxcExpand SRC:http://www.vicsjavascripts.org.uk/StdImages/Egypt6.jpg Duration:500 YOffset:-30" src="http://www.vicsjavascripts.org.uk/StdImages/Egypt5.jpg" />
    <img class="img zxcExpand XOffset:-205" src="http://www.vicsjavascripts.org.uk/StdImages/Egypt5.jpg" />
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #5
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That's what i want . Thank you very much vwphilips .


  •  

    Posting Permissions

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