RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
怎么用jQuery和CSS实现缩略图悬浮逼近效果

这篇文章主要讲解了“怎么用jQuery和CSS实现缩略图悬浮逼近效果”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么用jQuery和CSS实现缩略图悬浮逼近效果”吧!

创新互联是一家专注于网站制作、成都网站建设与策划设计,惠水网站建设哪家好?创新互联做网站,专注于网站建设十载,网设计领域的专业建站公司;建站业务涵盖:惠水等地区。惠水做网站价格咨询:18982081108

今天我们为大家介绍一个使用jQuery实现的缩略图逼近效果。主要的想法是当鼠标接近缩略图后,当前的缩略图会放大,并且周围相邻的缩略图也会相应变大一些,当你移动鼠标时,会影响移动方向上的缩略图大小变化,具体效果请大家查看演示。

实例下载

你可以在这个网站/upload/otherpic68/474763.com" /> 

  •              

  •                 

    Time

     

  •                 

    Since time, and his predestinated end

     

  •             

 

  •     

  •  

  •     

  •  

  •  

  • CSS样式

    以下定义了缩略图居中,并且添加背景图片使得图片产生透明度变化效果

    pe-thumbs{      width: 900px;      height: 400px;      margin: 20px auto;      position: relative;      background: transparent url(../images/3.jpg) top center;      border: 5px solid #fff;      box-shadow: 0 1px 2px rgba(0,0,0,0.2);  }

    同时我们也使用一个RGBA的背景颜色添加一个小点缀到背景图片。

    .pe-thumbs:before {      content: "";      display: block;      position: absolute;      top: 0px;      left: 0px;      width: 100%;      height: 100%;      background: rgba(255,102,0,0.2);  }

    列表中的项目将会向左float,并且我们设置锚定和图片的相对位置:

    .pe-thumbs li{      float: left;      position: relative;  }  .pe-thumbs li a,  .pe-thumbs li a img{      display: block;      position: relative;  }

    每一个缩略图都初始100px并且透明度为0.2:

    .pe-thumbs li a img{      width: 100px;      opacity: 0.2;  }

    ***我们定义描述内容的样式:

    .pe-description h4{      padding: 10px 10px 0px 10px;      line-height: 20px;      font-family: 'BebasNeueRegular', 'Arial Narrow', Arial, sans-serif;      font-size: 22px;      margin: 0px;  }  .pe-description p{      padding: 10px 0px;      margin: 10px;      font-size: 11px;      font-style: italic;      border-top: 1px solid rgba(255,255,255,0.3);  }

    JavaScript代码

    主要的想法是当鼠标悬浮后计算所有的描述容器大小和位置。主要依赖于缩略图的***尺寸及其居于主要wrapper中的位置。例如,当缩略图接近边缘,我们就使得描述区域显示在缩略图左边

    然后我们将帮定逼近事件到图片。主要想法是根据鼠标位置来变化图片大小。一旦图片达到***尺寸,我们设置z-index***,因此位于***层次,并且显示分开的描述。

    // list of thumbs  var $list        = $('#pe-thumbs'),      // list's width and offset left.      // this will be used to know the position of the description container      listW        = $list.width(),      listL        = $list.offset().left,      // the images      $elems        = $list.find('img'),      // the description containers      $descrp        = $list.find('div.pe-description'),      // maxScale : maximum scale value the image will have      // minOpacity / maxOpacity : minimum (set in the CSS) and maximum values for the image's opacity      settings    = {          maxScale    : 1.3,          maxOpacity    : 0.9,          minOpacity    : Number( $elems.css('opacity') )      },      init        = function() {           // minScale will be set in the CSS          settings.minScale = _getScaleVal() || 1;          // preload the images (thumbs)          _loadImages( function() {               _calcDescrp();              _initEvents();           });       },      // Get Value of CSS Scale through JavaScript:      // http://css-tricks.com/get-value-of-css-rotation-through-javascript/      _getScaleVal= function() {           var st = window.getComputedStyle($elems.get(0), null),              tr = st.getPropertyValue("-webkit-transform") ||                   st.getPropertyValue("-moz-transform") ||                   st.getPropertyValue("-ms-transform") ||                   st.getPropertyValue("-o-transform") ||                   st.getPropertyValue("transform") ||                   "fail...";           if( tr !== 'none' ) {                    var values = tr.split('(')[1].split(')')[0].split(','),                  a = values[0],                  b = values[1],                  c = values[2],                  d = values[3];               return Math.sqrt( a * a + b * b );           }       },      // calculates the style values for the description containers,      // based on the settings variable      _calcDescrp    = function() {           $descrp.each( function(i) {               var $el        = $(this),                  $img    = $el.prev(),                  img_w    = $img.width(),                  img_h    = $img.height(),                  img_n_w    = settings.maxScale * img_w,                  img_n_h    = settings.maxScale * img_h,                  space_t = ( img_n_h - img_h ) / 2,                  space_l = ( img_n_w - img_w ) / 2;               $el.data( 'space_l', space_l ).css({                  height    : settings.maxScale * $el.height(),                  top        : -space_t,                  left    : img_n_w - space_l              });           });       },      _initEvents    = function() {           $elems.on('proximity.Photo', { max: 80, throttle: 10, fireOutOfBounds : true }, function(event, proximity, distance) {               var $el            = $(this),                  $li            = $el.closest('li'),                  $desc        = $el.next(),                  scaleVal    = proximity * ( settings.maxScale - settings.minScale ) + settings.minScale,                  scaleExp    = 'scale(' + scaleVal + ')';               // change the z-index of the element once              // it reaches the maximum scale value              // also, show the description container              if( scaleVal === settings.maxScale ) {                   $li.css( 'z-index', 1000 );                   if( $desc.offset().left + $desc.width() > listL + listW ) {                       $desc.css( 'left', -$desc.width() - $desc.data( 'space_l' ) );                   }                   $desc.fadeIn( 800 );               }              else {                   $li.css( 'z-index', 1 );                   $desc.stop(true,true).hide();               }                   $el.css({                  '-webkit-transform'    : scaleExp,                  '-moz-transform'    : scaleExp,                  '-o-transform'        : scaleExp,                  '-ms-transform'        : scaleExp,                  'transform'            : scaleExp,                  'opacity'            : ( proximity * ( settings.maxOpacity - settings.minOpacity ) + settings.minOpacity )              });           });       },      _loadImages    = function( callback ) {           var loaded     = 0,              total    = $elems.length;           $elems.each( function(i) {               var $el = $(this);               $('').load( function() {                   ++loaded;                  if( loaded === total )                      callback.call();               }).attr( 'src', $el.attr('src') );           });       };   return {      init    : init  };

    感谢各位的阅读,以上就是“怎么用jQuery和CSS实现缩略图悬浮逼近效果”的内容了,经过本文的学习后,相信大家对怎么用jQuery和CSS实现缩略图悬浮逼近效果这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!


    分享名称:怎么用jQuery和CSS实现缩略图悬浮逼近效果
    本文来源:http://sczitong.cn/article/popecp.html