// JavaScript Document String.prototype.trim = function () { var str = this, str = str.replace(/^\s+/, ''); for (var i = str.length - 1; i >= 0; i--) { if (/\S/.test(str.charAt(i))) { str = str.substring(0, i + 1); break; } } return str; } Array.prototype.Contain = function (item) { var array = this; for (var i = array.length - 1; i >= 0; i--) { if (array[i] == item) return true; } return false; } /*取cookies*/ var getCookie = function (c_name) { if (document.cookie.length > 0) { c_start = document.cookie.indexOf(c_name + "="); if (c_start != -1) { c_start = c_start + c_name.length + 1; c_end = document.cookie.indexOf(";", c_start); if (c_end == -1) c_end = document.cookie.length; return decodeURIComponent(document.cookie.substring(c_start, c_end)); } } return ""; } //设为首页 var sethomepage = function (url) { if (document.all) { document.body.style.behavior = 'url(#default#homepage)'; document.body.setHomePage(window.location.href); } else if (window.sidebar) { if (window.netscape) { try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); } catch (e) { alert("该操作被浏览器拒绝,如果想启用该功能,请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true"); } } var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch); prefs.setCharPref('browser.startup.homepage', window.location.href); } else { alert('您的浏览器不支持自动设置首页, 请使用浏览器菜单手动设置!'); } } //加入收藏 var addfav = function () { if (document.all) { try { window.external.addFavorite(window.location.href, document.title); } catch (e) { alert("加入收藏失败,请使用Ctrl+D进行添加"); } } else if (window.sidebar) { window.sidebar.addPanel(document.title, window.location.href, ""); } else { alert("加入收藏失败,请使用Ctrl+D进行添加"); } } //图片缩放 参数(图片,允许的宽度,允许的高度) function DrawImage(ImgD, iwidth, iheight) { var image = new Image(); image.src = ImgD.src; if (image.width > 0 && image.height > 0) { if (0==iheight||(image.width / image.height) >= (iwidth / iheight)) { if (image.width > iwidth) { ImgD.width = iwidth; ImgD.height = (image.height * iwidth) / image.width; } else { ImgD.width = image.width; ImgD.height = image.height; } } else { if (image.height > iheight) { ImgD.height = iheight; ImgD.width = (image.width * iheight) / image.height; } else { ImgD.width = image.width; ImgD.height = image.height; } } } } /*********瀑布流图片展示***********/ //var config = { // CellCount:3, // CellSeparated:0, // CellWidth:320, // RowSepareted:0, // BoxId:"", // Item:"", // More_bottom:"", // More_url:"" //}; var flowImage = function (config) { var _cell = new Array(config.CellCount); var _box = $(config.BoxId); var _index = 0; var _itemIndex = 0; var pageIndex = 2; var Init = function () { var _cellItem = { left: 0,top: 0 }; _cell[0] = { left: 0,top: 0 }; for (var i = 1; i < config.CellCount; i++) { _cell[i] = { left: _cell[i - 1].left + config.CellSeparated + config.CellWidth,top: 0 }; } _index = GetCell(); _itemIndex = 0; _pageIndex = 1; }; var Flow = function () { InitItem(_box.children(config.Item)); _box.height(GetMaxCellTop()); }; var InitItem = function (list) { for (var i = _itemIndex; i < list.length; i++) { var $this = list.eq(i); var $img = $this.find("img"); DrawImage($img[0],312,0); $this.css({ top: _cell[_index].top,left: _cell[_index].left,position: "absolute",display: "block" }); _cell[_index].top = _cell[_index].top + $img.height() + 70 + config.RowSepareted; _index = GetCell(); } _itemIndex = list.length; }; var GetCell = function () { var top = _cell[0].top,index = 0; if (0 == top) { return 0; } for (var i = 1; i < _cell.length; i++) { if (0 == _cell[i].top) { index = i; break; } if (_cell[i].top < top) { top = _cell[i].top; index = i; } } return index; }; var GetMaxCellTop = function () { var top = _cell[0].top; for (var i = 1; i < _cell.length; i++) { if (_cell[i].top > top) { top = _cell[i].top; } } return top; }; Init(); Flow(); $(config.More_bottom).click(function () { var url = config.More_url; if (url.indexOf("?") == -1) { url = url + "?page=" + pageIndex; } else { url = url + "&page=" + pageIndex; } $.ajax({ type: "GET", url: url, dataType: "html", cache: false, success: function (html) { _box.append(html); Flow(); } }); pageIndex++; }); }