www.webdeveloper.com
Results 1 to 4 of 4

Thread: Controlling Image Windows on Mouseover

Hybrid View

  1. #1
    Join Date
    Apr 2012
    Posts
    2

    Controlling Image Windows on Mouseover

    Some time back I came across a site that used a small version of an image as the legend for a larger version of the same image. The small version was displayed in full, but the larger version was displayed in a window of reduced size. When you moved the mouse over the small image the same area of the larger image was displayed in its window. I hope this makes sense. I'm trying to figure out how to do this? Can someone point me in the right direction?

  2. #2
    Join Date
    Jun 2004
    Location
    Portsmouth UK
    Posts
    2,709
    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>
    </head>
    
    <body>
    <img id="p1" src='http://www.ezilon.com/maps/images/world-physical-map.gif' style="width:300px;">
    <div id="p1M" style="position:relative;width:400px;height:300px;border:solid red 1px;" >
    <img src='http://www.ezilon.com/maps/images/world-physical-map.gif' style="width:300%;">
    </div>
    <script> vic=0; </script>
    <form name=Show id=Show style="position:absolute;visibility:visible;top:700px;left:0px;" >
    <input size=100 name=Show0 >
    <input size=10 name=Show1 >
    <input size=10 name=Show2 >
    <input size=10 name=Show3 >
    <input size=10 name=Show4 >
    <input size=10 name=Show5 >
    <input size=10 name=Show6 >
    <input size=10 name=Show7 >
    <input size=10 name=Show8 >
    <input size=10 name=Show9 ><br>
    <textarea name=TA rows=1 cols=100 ></textarea>
    </form>
    
    <script type="text/javascript">
    /*<![CDATA[*/
    
    var zxcPan={
    
     init:function(o){
      var img=document.getElementById(o.ID),mp=document.getElementById(o.MainID),mimg=mp.getElementsByTagName('IMG')[0],obj;
      mp.style.overflow='hidden';
      mimg.style.position='absolute';
      obj={
       img:img,
       mp:mp,
       mimg:mimg,
       osx:mp.offsetWidth/2,
       osy:mp.offsetHeight/2
      }
      this.addevt(img,'mousemove','pan',obj);
     },
    
    
     pan:function(e,obj){
      var m=this.mse(e),p=this.pos(obj.img),x=m[0]-p[0],y=m[1]-p[1],w=obj.mimg.width,h=obj.mimg.height;
      obj.mimg.style.left=Math.max(Math.min(-x/(obj.img.width/w)+obj.osx,0),-w+obj.osx*2)+'px';
      obj.mimg.style.top=Math.max(Math.min(-y/(obj.img.height/h)+obj.osy,0),-h+obj.osy*2)+'px';
     },
    
     pos:function(obj){
      var rtn=[0,0];
      while(obj){
       rtn[0]+=obj.offsetLeft;
       rtn[1]+=obj.offsetTop;
       obj=obj.offsetParent;
      }
      return rtn;
     },
    
     mse:function(e){
      if (window.event){
       var docs=[document.body.scrollLeft,document.body.scrollTop];
       if (!document.body.scrollTop){
        docs=[document.documentElement.scrollLeft,document.documentElement.scrollTop];
       }
       return [e.clientX+docs[0],e.clientY+docs[1]];
      }
      return [e.pageX,e.pageY];
     },
    
     addevt:function(o,t,f,p){
      var oop=this;
      if (o.addEventListener) o.addEventListener(t,function(e){ return oop[f](e,p);}, false);
      else if (o.attachEvent) o.attachEvent('on'+t,function(e){ return oop[f](e,p); });
     }
    
    }
    
    zxcPan.init({
     ID:'p1',
     MainID:'p1M'
    });
    /*]]>*/
    </script>
    </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/

  3. #3
    Join Date
    Apr 2012
    Posts
    2

    Followup Question

    Thanks Vic. I think I understand most of the code. Is this copyrighted? I'd like to use parts of it with our history museum web site.

  4. #4
    Join Date
    Jun 2004
    Location
    Portsmouth UK
    Posts
    2,709
    use it as you wish

    including credits would be good

    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>
    </head>
    
    <body>
    <img id="p1" src='http://www.ezilon.com/maps/images/world-physical-map.gif' style="width:300px;">
    <div id="p1M" style="position:relative;width:400px;height:300px;border:solid red 1px;" >
    <img src='http://www.ezilon.com/maps/images/world-physical-map.gif' style="width:300&#37;;">
    </div>
    
    <script type="text/javascript">
    /*<![CDATA[*/
    // Pan Image (01-May-2012)
    // by Vic Phillips - http://www.vicsjavascripts.org.uk/
    
    var zxcPan={
    
     init:function(o){
      var img=document.getElementById(o.ID),mp=document.getElementById(o.MainID),mimg=mp.getElementsByTagName('IMG')[0],obj;
      mp.style.overflow='hidden';
      mimg.style.position='absolute';
      obj={
       img:img,
       mp:mp,
       mimg:mimg,
       osx:mp.offsetWidth/2,
       osy:mp.offsetHeight/2
      }
      this.addevt(img,'mousemove','pan',obj);
     },
    
    
     pan:function(e,obj){
      var m=this.mse(e),p=this.pos(obj.img),x=m[0]-p[0],y=m[1]-p[1],w=obj.mimg.width,h=obj.mimg.height;
      obj.mimg.style.left=Math.max(Math.min(-x/(obj.img.width/w)+obj.osx,0),-w+obj.osx*2)+'px';
      obj.mimg.style.top=Math.max(Math.min(-y/(obj.img.height/h)+obj.osy,0),-h+obj.osy*2)+'px';
     },
    
     pos:function(obj){
      var rtn=[0,0];
      while(obj){
       rtn[0]+=obj.offsetLeft;
       rtn[1]+=obj.offsetTop;
       obj=obj.offsetParent;
      }
      return rtn;
     },
    
     mse:function(e){
      if (window.event){
       var docs=[document.body.scrollLeft,document.body.scrollTop];
       if (!document.body.scrollTop){
        docs=[document.documentElement.scrollLeft,document.documentElement.scrollTop];
       }
       return [e.clientX+docs[0],e.clientY+docs[1]];
      }
      return [e.pageX,e.pageY];
     },
    
     addevt:function(o,t,f,p){
      var oop=this;
      if (o.addEventListener) o.addEventListener(t,function(e){ return oop[f](e,p);}, false);
      else if (o.attachEvent) o.attachEvent('on'+t,function(e){ return oop[f](e,p); });
     }
    
    }
    
    zxcPan.init({
     ID:'p1',
     MainID:'p1M'
    });
    /*]]>*/
    </script>
    </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/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.26490 seconds
  • Memory Usage 2,987KB
  • Queries Executed 13 (?)
More Information
Template Usage (30):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (2)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (4)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (4)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)showthread_list
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (27):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./includes/functions_threadedmode.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids_threaded
  • showthread_threaded_construct_link
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates