?function () { var indexHandler = function () { //首页焦点? function handlerFocusBox() { $(".focusBox").slide({ titCell: ".num", mainCell: ".pic", effect: "fold", autoPlay: true, autoPage: '
  • $
  • ', trigger: "click", startFun: function (i) { jQuery(".focusBox .txt li") .eq(i) .animate({ "bottom": 0 }) .siblings().animate({ "bottom": -36 }); } }).hover( function () { $(".prev,.next", this).stop().fadeIn(); }, function () { $(".prev,.next", this).stop().fadeOut(); } ); } //香R女 function handlerPhotoWall() { //$("#image-container img").each(function () { // var src = $(this).attr("src"); // $(this).attr("src", ""); // $(this).attr("src", src); //}); function onProgress(imgLoad, image) { //每加载一个图片调用一? var $item = $(image.img).closest("li"); $item.removeClass('loading'); if (!image.isLoaded) { $item.remove(); } } function onAllloaded() { var BASEHEIGHT = 120;//基准高度; var rowsArr = [], colArr = [];//所有的行,二维数组 var $items = $("#image-container").children(), len = $items.length; $items.each(function (index, element) { //element是一个dom对象Q? var $this = $(this), curtop = $this.offset().top, pretop = 0;//上个元素的偏U量 if (index > 0 && colArr.length > 0) { var $preitem = colArr[colArr.length - 1]; pretop = $preitem.offset().top; } if (Math.abs(pretop - curtop) < 10) { //表示在同一? colArr.push($this); } else { //当前元素与上一个元素在不同的行 //列集合插入行集合中 if (colArr !== undefined && colArr.length > 0) { rowsArr.push(colArr); } colArr = [$this]; } if (index === (len - 1)) { //最后一个行元素 if (colArr.length > 0) { rowsArr.push(colArr); } } }); //rowsArr,是一个二l数l;每个数组x的是一个数l? var BASEWIDTH = 0, MAXSCALE = 1.5;//容器的宽? for (var i = 0, len = rowsArr.length; i < len; i++) { var colArr = rowsArr[i]; //存在本行的所有元? //如何获取本行的元素呢; if (BASEWIDTH <= 0) { BASEWIDTH = colArr[0].parent().width(); //UL宽度 } var lineOuterWidth = 0,//当前行宽, lineWidth = 0; for (var j = 0, len1 = colArr.length; j < len1; j++) { lineOuterWidth += colArr[j].outerWidth(true); //获取LI的宽? lineWidth += parseInt(colArr[j].css("width")); } var totalSpaceWidth = lineOuterWidth - lineWidth;//间隙 var scale = (BASEWIDTH - totalSpaceWidth) / lineWidth; //每个元素需要羃攄比例 var tarheight = Math.floor(colArr[0].height() * scale); var linegap = 0;//行的宽度误差 var isvalidRow = true; for (var j = 0, len1 = colArr.length; j < len1; j++) { //每个元素应用~放 var $item = colArr[j]; if (scale >= MAXSCALE) {//过~放临界|U除 Q? isvalidRow = false;//标示为无效的行; $item.remove(); } else { var temp = $item.width() * scale, //会有误差 tarwidth = Math.floor(temp); linegap += (temp - tarwidth); $item.width(tarwidth); $item.height(tarheight); } } if (isvalidRow) { //处理行误?d到行的第一个元素的margin? var index = parseInt(Math.random() * colArr.length); if (index == colArr.length - 1) { --index; index = index < 0 ? 0 : index; } var $firitem = colArr[index]; var tarmarginRight = parseInt($firitem.css("margin-right")) + linegap; $firitem.css("margin-right", tarmarginRight); } } colArr = null; rowsArr = null; } $("#image-container").imagesLoaded() .progress(onProgress) .always(onAllloaded); } return { init: function () { var $slider_txt = $('.focusBox .txt'); $('.focusBox .pic li').each(function (i, x) { var $item = $(this); $slider_txt.append( $('
  • ').append( $('').attr({ href: $item.find('a').attr('href'), target: '_blank' }).text($item.find('img').attr('alt')) ) ); }); handlerFocusBox(); //handlerPhotoWall(); } } }(); $(function () { indexHandler.init(); }); })(); òСҳ