jquery模仿京东商品图,在鼠标指向时稍微放大一点

2290阅读 0评论2016-07-09 lsstarboy
分类:jQuery

直接上代码:

  1. $(".img-hover").hover(
  2.    function(){
  3.           $(this).parent().width( $(this).parent().width());
  4.           $(this).parent().height( $(this).parent().height());
  5.           $(this).parent().css({ 'padding':"-10px" });
  6.   },
  7.    function(){
  8.           $(this).parent().removeAttr("style");
  9.   });
说明:
1、.img-hover为图片的类;
2、parent类必须设置一个padding,至少10px以上才有效果。
3、原理是:先定死上级div的高度和宽度,然后再放大图片。

示例html代码:

  1. <div class="panel-heading">
  2.       <img class="img-responsive img-portfolio img-hover" src="/front/img/p1.jpg" alt="">
  3. </div>


上一篇:FreeBSD下ruby安装json出错(FreeBSD下强制ruby版本)
下一篇:webuploader放入bootstap的tab-content时,不能正确初始化