JQ 瀑布流的插件
程序员文章站
2022-05-17 22:17:48
...
<!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8"> <title>JQ 瀑布流的插件</title> <link rel="stylesheet" href="base.css" /> <style type="text/css"> a{text-decoration:none; color:#333; -webkit-transition: color .2s;-moz-transition: color .2s;-o-transition: color .2s; -ms-transition: color .2s;transition: color .2s;} a:hover{text-decoration:underline; color: #ff7d8e;} a:focus{outline:none;} ::selection {background:#ff7d8e; color:#fff;} .wrapper{width: 1008px; margin: 15px auto;} .brand-list{width: 1100px; overflow: hidden; margin-left: -10px;} .brand-list .brand-bd{position: relative; margin-left: 10px; margin-top: 5px;} .brand-list .item{position: absolute; width: 202px; background-color: #f8f8f8; border: 1px solid #f8f8f8; padding: 18px; top:0; left: 40%; -webkit-transition: all 0.3s;-moz-transition: all 0.3s;-o-transition: all 0.3s;-ms-transition: all 0.3s;transition: all 0.3s;} .brand-list .hover{box-shadow: 0px 1px 8px rgba(200,200,200,.6); background-color: #fff; border-color: #c8c8c8;} .brand-list .additem{padding: 0; width: 240px; border: none; } .brand-list .item h3{font-size: 42px; color: #666; font-family: arial; font-weight: bold; line-height: .8; margin-bottom: 20px;} .brand-list .item p{margin-bottom: 15px;} </style> </head> <body> <div class="wrapper"> <div class="brand-list"> <div class="brand-bd cle" id="brand-waterfall"> <div class="item"> <h3>A</h3> <p><a href="#" target="_blank">ARDELL/艾黛尔</a></p> <p><a href="#" target="_blank">ANNASUI/安娜苏</a></p> <p><a href="#" target="_blank">ETUDEHOUSE/爱丽小屋</a></p> <p><a href="#" target="_blank">abeeco</a></p> <p><a href="#" target="_blank">AFU/阿芙</a></p> <p><a href="#" target="_blank">Egyptian-Magic-Cream/埃及魔法膏</a></p> <p><a href="#" target="_blank">adidas/阿迪达斯</a></p> </div> <div class="item"> <h3>B</h3> <p><a href="#" target="_blank">HERBORIST/佰草集</a></p> <p><a href="#" target="_blank">BURBERRY/巴宝莉/博柏利</a></p> <p><a href="#" target="_blank">BIOTHERM/碧欧泉</a></p> <p><a href="#" target="_blank">benefit/贝玲妃</a></p> <p><a href="#" target="_blank">Bavii/柏羽</a></p> <p><a href="#" target="_blank">PaulSmith/保罗史密夫</a></p> <p><a href="#" target="_blank">Bobbi Brown/芭比布朗</a></p> <p><a href="#" target="_blank">BVLGARI/宝格丽</a></p> <p><a href="#" target="_blank">PURE&MILD/泊美</a></p> <p><a href="#" target="_blank">baviphat/芭比菲特</a></p> <p><a href="#" target="_blank">Peter Thomas Roth/彼得罗夫</a></p> <p><a href="#" target="_blank">BeDOOK/比度克</a></p> <p><a href="#" target="_blank">BIODERMA/贝德玛</a></p> <p><a href="#" target="_blank">BKBarry-MBlistex/碧唇</a></p> </div> <div class="item"> <h3>C</h3> <p><a href="#" target="_blank">Fenix/长生鸟</a></p> <p><a href="#" target="_blank">For Beloved One/宠爱之名</a></p> <p><a href="#" target="_blank">CHARMZONE/婵真</a></p> </div> <div class="item"> <h3>D</h3> <p><a href="#" target="_blank">Dr.Jart+Dr.MJDior/迪奥</a></p> <p><a href="#" target="_blank">dodo</a></p> <p><a href="#" target="_blank">Dior/迪奥</a></p> <p><a href="#" target="_blank">Dove/多芬</a></p> <p><a href="#" target="_blank">DHC/蝶翠诗</a></p> <p><a href="#" target="_blank">Davidoff/大卫杜夫</a></p> </div> <div class="item"> <h3>E</h3> <p><a href="#" target="_blank">N-Dorphin/恩朵娉</a></p> <p><a href="#" target="_blank">OPERA/娥佩兰</a></p> <p><a href="#" target="_blank">ELF</a></p> <p><a href="#" target="_blank">eos</a></p> </div> <div class="item"> <h3>F</h3> <p><a href="#" target="_blank">芳草集</a></p> <p><a href="#" target="_blank">THEFACESHOP/菲诗小铺</a></p> <p><a href="#" target="_blank">Fanxishop/凡茜</a></p> <p><a href="#" target="_blank">FANCL/芳珂(芳凯尔)</a></p> <p><a href="#" target="_blank">VERSACE/范思哲</a></p> </div> <div class="item"> <h3>G</h3> <p><a href="#" target="_blank">ARDELL/艾黛尔</a></p> <p><a href="#" target="_blank">ANNASUI/安娜苏</a></p> <p><a href="#" target="_blank">ETUDEHOUSE/爱丽小屋</a></p> <p><a href="#" target="_blank">abeeco</a></p> <p><a href="#" target="_blank">AFU/阿芙</a></p> <p><a href="#" target="_blank">Egyptian-Magic-Cream/埃及魔法膏</a></p> <p><a href="#" target="_blank">adidas/阿迪达斯</a></p> </div> <div class="item"> <h3>H</h3> <p><a href="#" target="_blank">LAMER/海蓝之谜</a></p> <p><a href="#" target="_blank">BOCOTON/海诺丝丽</a></p> <p><a href="#" target="_blank">CO.E/韩伊</a></p> <p><a href="#" target="_blank">Herbacin/贺本清</a></p> <p><a href="#" target="_blank">花瑶花</a></p> <p><a href="#" target="_blank">花漾美姬</a></p> <p><a href="#" target="_blank">HEY NATURE/韩彩妮</a></p> <p><a href="#" target="_blank">Hipitch/黑龙堂</a></p> </div> <div class="item"> <h3>L</h3> <p><a href="#" target="_blank">LAMER/海蓝之谜</a></p> <p><a href="#" target="_blank">BOCOTON/海诺丝丽</a></p> <p><a href="#" target="_blank">CO.E/韩伊</a></p> <p><a href="#" target="_blank">CO.E/韩伊</a></p> <p><a href="#" target="_blank">CO.E/韩伊</a></p> <p><a href="#" target="_blank">Herbacin/贺本清</a></p> <p><a href="#" target="_blank">花瑶花</a></p> <p><a href="#" target="_blank">花漾美姬</a></p> <p><a href="#" target="_blank">HEY NATURE/韩彩妮</a></p> <p><a href="#" target="_blank">Hipitch/黑龙堂</a></p> </div> <div class="item"> <h3>M</h3> <p><a href="#" target="_blank">LAMER/海蓝之谜</a></p> <p><a href="#" target="_blank">BOCOTON/海诺丝丽</a></p> <p><a href="#" target="_blank">CO.E/韩伊</a></p> <p><a href="#" target="_blank">Herbacin/贺本清</a></p> <p><a href="#" target="_blank">花瑶花</a></p> <p><a href="#" target="_blank">花漾美姬</a></p> <p><a href="#" target="_blank">HEY NATURE/韩彩妮</a></p> <p><a href="#" target="_blank">Hipitch/黑龙堂</a></p> </div> <div class="item"> <h3>N</h3> <p><a href="#" target="_blank">LAMER/海蓝之谜</a></p> <p><a href="#" target="_blank">LAMER/海蓝之谜</a></p> <p><a href="#" target="_blank">LAMER/海蓝之谜</a></p> <p><a href="#" target="_blank">BOCOTON/海诺丝丽</a></p> <p><a href="#" target="_blank">CO.E/韩伊</a></p> <p><a href="#" target="_blank">Herbacin/贺本清</a></p> <p><a href="#" target="_blank">花瑶花</a></p> <p><a href="#" target="_blank">花漾美姬</a></p> <p><a href="#" target="_blank">HEY NATURE/韩彩妮</a></p> <p><a href="#" target="_blank">Hipitch/黑龙堂</a></p> </div> </div> </div> </div> <script type="text/javascript" src="jquery-1.10.1.min.js" ></script> <script> $(function(){ $('#brand-waterfall').waterfall(); }); ;(function ($) { $.fn.waterfall = function(options) { var df = { item: '.item', margin: 15, addfooter: true }; options = $.extend(df, options); return this.each(function() { var $box = $(this), pos = [], _box_width = $box.width(), $items = $box.find(options.item), _owidth = $items.eq(0).outerWidth() + options.margin, _oheight = $items.eq(0).outerHeight() + options.margin, _num = Math.floor(_box_width/_owidth); (function() { var i = 0; for (; i < _num; i++) { pos.push([i*_owidth,0]); } })(); $items.each(function() { var _this = $(this), _temp = 0, _height = _this.outerHeight() + options.margin; _this.hover(function() { _this.addClass('hover'); },function() { _this.removeClass('hover'); }); for (var j = 0; j < _num; j++) { if(pos[j][1] < pos[_temp][1]){ _temp = j; } } this.style.cssText = 'left:'+pos[_temp][0]+'px; top:'+pos[_temp][1]+'px;'; pos[_temp][1] = pos[_temp][1] + _height; }); (function() { var i = 0, tops = []; for (; i < _num; i++) { tops.push(pos[i][1]); } tops.sort(function(a,b) { return a-b; }); $box.height(tops[_num-1]); if(options.addfooter){ addfooter(tops[_num-1]); } })(); function addfooter(max) { var addfooter = document.createElement('div'); addfooter.className = 'item additem'; for (var i = 0; i < _num; i++) { if(max != pos[i][1]){ var clone = addfooter.cloneNode(), _height = max - pos[i][1] - options.margin; clone.style.cssText = 'left:'+pos[i][0]+'px; top:'+pos[i][1]+'px; height:'+_height+'px;'; $box[0].appendChild(clone); } } } }); } })(jQuery); </script> </body> </html>
效果图: