cathyForever
 1 $(\'.imgUl li,.v_img\').click(function(){
 2         var _left = 0;
 3         var _top = 0;
 4         $(\'body\').append(\'<div class="pop"><div class="pop_con"><a href="javascript:;" class="img_close"><img src="images/img_close.png"></a><img src="\'+$(this).children(\'.pic-off\').attr(\'rel\')+\'" class="pic_b"/></div></div>\');
 5         var newImg = new Image();
 6         newImg.onload = function(){
 7             _h = newImg.height;
 8             _w = newImg.width;
 9             $(\'.opacityDiv\').show();
10             _left = \'-\'+parseInt(_w)/2+\'px\';
11             _top = \'-\'+parseInt(_h)/2+\'px\';
12             $(\'.pop\').css({\'margin-left\':\'-\'+parseInt(_w)/2+\'px\',\'margin-top\':_top});
13             $(\'.img_close\').click(function(){
14                 $(\'.opacityDiv\').hide();
15                 $(\'.pop\').remove();
16             });
17             }
18             newImg.src = $(this).children(\'.pic-off\').attr(\'rel\');
19     });

注:图片在缓存加载时获取的宽度和高度都为0,所以newImg.onload方法可以将图片加载完成后再获取本身的宽高。此时获取的值均为正确的值。

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-04
  • 2022-12-23
  • 2022-12-23
  • 2021-10-14
  • 2021-11-28
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-28
  • 2022-12-23
  • 2022-01-04
  • 2021-12-20
  • 2022-12-23
  • 2021-12-23
相关资源
相似解决方案