简体   繁体   中英

on Hover Image zoom

I am trying to implement on hover zoom on a image, i found some code in google. But it is giving me unwanted result. The image zoom is appearing at the corner of the window.

 <img id="a1" src="http://demos.frnzzz.com/imgZoom/1.jpg" height="50" width="50">
 <img id="a2" src="http://demos.frnzzz.com/imgZoom/1.jpg" height="50" width="50">

Code i have used is

  $(function()
  {
       $('img').hover(function()
       {
        $(this).css({'z-index' : '10'});
        $(this).animate({
        marginTop: '-110px', 
        marginLeft: '-110px', 
        top: '50%',
        left: '50%', 
        width: '174px', 
        height: '174px',
        padding: '10px'
       }, 500); 
     } , function() {
  $(this).css({'z-index' : '0'});
  $(this).animate({
   marginTop: '0', 
   marginLeft: '0',
   top: '0', 
   left: '0', 
   width: '70px', 
   height: '70px', 
   padding: '5px'
   }, 400);
  });
 });

This should do it for you:

http://jsfiddle.net/uCtHh/1/

Hope it helps.

Try this

 $(function()
  {
       $('img').hover(function()
       {
        $(this).css({'z-index' : '10'});
        $(this).animate({
        marginTop: '-110px', 
        marginLeft: '-110px', 
        top: '50%',
        left: '50%', 
        width: '174px', 
        height: '174px',
        padding: '10px',
        position: 'relative'
       }, 500); 
     } , function() {
  $(this).css({'z-index' : '0'});
  $(this).animate({
   marginTop: '0', 
   marginLeft: '0',
   top: '0', 
   left: '0', 
   width: '70px', 
   height: '70px', 
   padding: '5px',
   position: 'static'
   }, 400);
  });
 });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM