成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

使用jQuery和CSS實現超酷縮略圖懸浮逼近效果

開發 前端
今天我們為大家介紹一個使用jQuery實現的縮略圖逼近效果。主要的想法是當鼠標接近縮略圖后,當前的縮略圖會放大,并且周圍相鄰的縮略圖也會相應變大一些,當你移動鼠標時,會影響移動方向上的縮略圖大小變化,具體效果請大家查看演示。

今天我們為大家介紹一個使用jQuery實現的縮略圖逼近效果。主要的想法是當鼠標接近縮略圖后,當前的縮略圖會放大,并且周圍相鄰的縮略圖也會相應變大一些,當你移動鼠標時,會影響移動方向上的縮略圖大小變化,具體效果請大家查看演示。

實例下載

你可以在這個網站http://porscheeveryday.com/ 看到這個效果的原型,這里我們使用jQuery實現了一個jQuery版本的基本效果,希望大家喜歡!

在這個教程中,我們將使用James Padolsey的 jQuery Proximity plugin。

HTML標簽

以下代碼生成一個無序的縮略圖并且添加相關圖片描述:

  1. <ul id="pe-thumbs" class="pe-thumbs"> 
  2.     <li> 
  3.         <a href="#"> 
  4.             <img src="images/thumbs/1.jpg" /> 
  5.             <div class="pe-description"> 
  6.                 <h3>Time</h3> 
  7.                 <p>Since time, and his predestinated end</p> 
  8.             </div></a> 
  9.     </li> 
  10.     <li><!-- ... --></li> 
  11. </ul> 

CSS樣式

以下定義了縮略圖居中,并且添加背景圖片使得圖片產生透明度變化效果

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

同時我們也使用一個RGBA的背景顏色添加一個小點綴到背景圖片。

  1. .pe-thumbs:before {  
  2.     content: "";  
  3.     display: block;  
  4.     position: absolute;  
  5.     top: 0px;  
  6.     left: 0px;  
  7.     width: 100%;  
  8.     height: 100%;  
  9.     background: rgba(255,102,0,0.2);  
  10. }  

列表中的項目將會向左float,并且我們設置錨定和圖片的相對位置:

  1. .pe-thumbs li{  
  2.     float: left;  
  3.     position: relative;  
  4. }  
  5. .pe-thumbs li a,  
  6. .pe-thumbs li a img{  
  7.     display: block;  
  8.     position: relative;  
  9. }  

每一個縮略圖都初始100px并且透明度為0.2:

  1. .pe-thumbs li a img{  
  2.     width: 100px;  
  3.     opacity: 0.2;  

***我們定義描述內容的樣式:

  1. .pe-description h3{  
  2.     padding: 10px 10px 0px 10px;  
  3.     line-height: 20px;  
  4.     font-family: 'BebasNeueRegular', 'Arial Narrow', Arial, sans-serif;  
  5.     font-size: 22px;  
  6.     margin: 0px;  
  7. }  
  8. .pe-description p{  
  9.     padding: 10px 0px;  
  10.     margin: 10px;  
  11.     font-size: 11px;  
  12.     font-style: italic;  
  13.     border-top: 1px solid rgba(255,255,255,0.3);  
  14. }  

JavaScript代碼

主要的想法是當鼠標懸浮后計算所有的描述容器大小和位置。主要依賴于縮略圖的***尺寸及其居于主要wrapper中的位置。例如,當縮略圖接近邊緣,我們就使得描述區域顯示在縮略圖左邊

然后我們將幫定逼近事件到圖片。主要想法是根據鼠標位置來變化圖片大小。一旦圖片達到***尺寸,我們設置z-index***,因此位于***層次,并且顯示分開的描述。

  1. // list of thumbs  
  2. var $list        = $('#pe-thumbs'),  
  3.     // list's width and offset left.  
  4.     // this will be used to know the position of the description container  
  5.     listW        = $list.width(),  
  6.     listL        = $list.offset().left,  
  7.     // the images  
  8.     $elems        = $list.find('img'),  
  9.     // the description containers  
  10.     $descrp        = $list.find('div.pe-description'),  
  11.     // maxScale : maximum scale value the image will have  
  12.     // minOpacity / maxOpacity : minimum (set in the CSS) and maximum values for the image's opacity  
  13.     settings    = {  
  14.         maxScale    : 1.3,  
  15.         maxOpacity    : 0.9,  
  16.         minOpacity    : Number( $elems.css('opacity') )  
  17.     },  
  18.     init        = function() {  
  19.  
  20.         // minScale will be set in the CSS  
  21.         settings.minScale = _getScaleVal() || 1;  
  22.         // preload the images (thumbs)  
  23.         _loadImages( function() {  
  24.  
  25.             _calcDescrp();  
  26.             _initEvents();  
  27.  
  28.         });  
  29.  
  30.     },  
  31.     // Get Value of CSS Scale through JavaScript:  
  32.     // http://css-tricks.com/get-value-of-css-rotation-through-javascript/  
  33.     _getScaleValfunction() {  
  34.  
  35.         var st = window.getComputedStyle($elems.get(0), null),  
  36.             tr = st.getPropertyValue("-webkit-transform") ||  
  37.                  st.getPropertyValue("-moz-transform") ||  
  38.                  st.getPropertyValue("-ms-transform") ||  
  39.                  st.getPropertyValue("-o-transform") ||  
  40.                  st.getPropertyValue("transform") ||  
  41.                  "fail...";  
  42.  
  43.         if( tr !== 'none' ) {       
  44.  
  45.             var values = tr.split('(')[1].split(')')[0].split(','),  
  46.                 a = values[0],  
  47.                 b = values[1],  
  48.                 c = values[2],  
  49.                 d = values[3];  
  50.  
  51.             return Math.sqrt( a * a + b * b );  
  52.  
  53.         }  
  54.  
  55.     },  
  56.     // calculates the style values for the description containers,  
  57.     // based on the settings variable  
  58.     _calcDescrp    = function() {  
  59.  
  60.         $descrp.each( function(i) {  
  61.  
  62.             var $el        = $(this),  
  63.                 $img    = $el.prev(),  
  64.                 img_w    = $img.width(),  
  65.                 img_h    = $img.height(),  
  66.                 img_n_w    = settings.maxScale * img_w,  
  67.                 img_n_h    = settings.maxScale * img_h,  
  68.                 space_t = ( img_n_h - img_h ) / 2,  
  69.                 space_l = ( img_n_w - img_w ) / 2;  
  70.  
  71.             $el.data( 'space_l', space_l ).css({  
  72.                 height    : settings.maxScale * $el.height(),  
  73.                 top        : -space_t,  
  74.                 left    : img_n_w - space_l  
  75.             });  
  76.  
  77.         });  
  78.  
  79.     },  
  80.     _initEvents    = function() {  
  81.  
  82.         $elems.on('proximity.Photo', { max: 80, throttle: 10, fireOutOfBounds : true }, function(event, proximity, distance) {  
  83.  
  84.             var $el            = $(this),  
  85.                 $li            = $el.closest('li'),  
  86.                 $desc        = $el.next(),  
  87.                 scaleVal    = proximity * ( settings.maxScale - settings.minScale ) + settings.minScale,  
  88.                 scaleExp    = 'scale(' + scaleVal + ')';  
  89.  
  90.             // change the z-index of the element once  
  91.             // it reaches the maximum scale value  
  92.             // also, show the description container  
  93.             if( scaleVal === settings.maxScale ) {  
  94.  
  95.                 $li.css( 'z-index', 1000 );  
  96.  
  97.                 if( $desc.offset().left + $desc.width() > listL + listW ) {  
  98.  
  99.                     $desc.css( 'left', -$desc.width() - $desc.data( 'space_l' ) );  
  100.  
  101.                 }  
  102.  
  103.                 $desc.fadeIn( 800 );  
  104.  
  105.             }  
  106.             else {  
  107.  
  108.                 $li.css( 'z-index', 1 );  
  109.  
  110.                 $desc.stop(true,true).hide();  
  111.  
  112.             }      
  113.  
  114.             $el.css({  
  115.                 '-webkit-transform'    : scaleExp,  
  116.                 '-moz-transform'    : scaleExp,  
  117.                 '-o-transform'        : scaleExp,  
  118.                 '-ms-transform'        : scaleExp,  
  119.                 'transform'            : scaleExp,  
  120.                 'opacity'            : ( proximity * ( settings.maxOpacity - settings.minOpacity ) + settings.minOpacity )  
  121.             });  
  122.  
  123.         });  
  124.  
  125.     },  
  126.     _loadImages    = function( callback ) {  
  127.  
  128.         var loaded     = 0,  
  129.             total    = $elems.length;  
  130.  
  131.         $elems.each( function(i) {  
  132.  
  133.             var $el = $(this);  
  134.  
  135.             $('<img>').load( function() {  
  136.  
  137.                 ++loaded;  
  138.                 if( loaded === total )  
  139.                     callback.call();  
  140.  
  141.             }).attr( 'src', $el.attr('src') );  
  142.  
  143.         });  
  144.  
  145.     };  
  146.  
  147. return {  
  148.     init    : init  
  149. };   

原文:http://www.cnblogs.com/gbin1/archive/2012/01/09/2317605.html

【編輯推薦】

  1. 11月Web技術最前沿:2011年度***jQuery插件揭曉
  2. 使用HTML 5、CSS3和jQuery增強網站用戶體驗
  3. 使用jQuery設計數據表格之設計表格基類
  4. 10月10款有趣強大的jQuery插件推薦
  5. 當jQuery遭遇CoffeeScript——妙不可言
責任編輯:陳貽新 來源: GBin1.com
相關推薦

2012-07-18 20:59:40

jQuery

2013-12-02 15:07:57

jQuery插件

2009-08-28 15:19:17

C#實現縮略圖

2013-08-12 15:26:49

測試

2009-10-26 17:38:22

VB.NET實現縮略圖

2019-02-15 14:00:57

Linux命令縮略圖

2009-12-07 11:21:59

PHP生成縮略圖

2009-08-28 10:22:13

Windows 7系統故障應對縮略圖無法顯示

2009-08-12 16:33:37

.NET生成縮略圖

2011-07-01 11:18:50

Qt 多線程

2010-01-20 10:29:37

Chrome縮略圖標簽管理

2011-05-04 09:05:39

Flash

2012-09-20 15:00:38

Win 8操作系統

2011-03-02 13:15:26

HTML 5jQuery

2023-05-15 17:04:33

Edge瀏覽器

2020-11-02 14:49:46

GitHub Java圖片

2022-02-21 16:38:19

Serverless圖片視頻

2011-08-17 15:08:08

windows7任務欄縮略圖

2014-07-14 12:37:36

jQueryCSS3

2010-09-13 10:23:06

CSS
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 丁香综合| 中文字幕在线视频观看 | 国产精品久久久久一区二区 | 午夜视频在线免费观看 | 草久久| 完全免费在线视频 | 久久综合久色欧美综合狠狠 | 91精品免费| 亚洲视频在线免费观看 | 久草网免费 | 欧美日韩综合视频 | 精品视频一区二区三区 | 欧美国产精品一区二区三区 | 亚洲最大av网站 | 日韩欧美一区二区三区免费观看 | 久久久精品国产 | 亚洲成人免费电影 | 91九色在线观看 | 久久精品国产a三级三级三级 | 日韩综合一区 | 国产精品亚洲一区二区三区在线观看 | 色综合久久88色综合天天 | 好婷婷网 | 在线观看中文字幕 | 亚洲一区二区三区视频免费观看 | 精品视频一区二区三区四区 | 日韩一级免费大片 | 在线免费观看a级片 | 九九久久精品视频 | 久久久久久国产精品免费免费 | 中文字幕精 | 在线观看亚洲一区二区 | 毛片一区二区三区 | 久久久tv| 极品一区 | 在线免费观看a级片 | 久久精品视频网站 | 久草在线 | 国产综合一区二区 | 亚洲精品在线播放 | 免费黄色a级毛片 |