diff --git a/src/core/wrapper/sticky/sticky.horizontal.js b/src/core/wrapper/sticky/sticky.horizontal.js new file mode 100644 index 000000000..f178afd6b --- /dev/null +++ b/src/core/wrapper/sticky/sticky.horizontal.js @@ -0,0 +1,38 @@ +/** + * 横向黏性布局 + */ +BI.HorizontalStickyLayout = BI.inherit(BI.FlexHorizontalLayout, { + props: function () { + return BI.extend(BI.HorizontalStickyLayout.superclass.props.apply(this, arguments), { + extraCls: "bi-h-sticky", + horizontalAlign: BI.HorizontalAlign.Stretch, + verticalAlign: BI.VerticalAlign.Stretch + }); + }, + + _addElement: function (i, item) { + var o = this.options; + var w = BI.HorizontalStickyLayout.superclass._addElement.apply(this, arguments); + var columnSize = o.columnSize.length > 0 ? o.columnSize[i] : item.width >= 1 ? null : item.width; + if (o.columnSize.length > 0) { + if (item.width >= 1 && o.columnSize[i] >= 1 && o.columnSize[i] !== item.width) { + columnSize = null; + } + } + if (columnSize !== "fill") { + var firstItemFill = o.columnSize[0] === "fill" || o.items[0].width === "fill"; + w.element.css({ + position: "sticky", + zIndex: 1, + left: firstItemFill ? "" : 0, + right: firstItemFill ? 0 : "" + }); + } else { + w.element.css({ + overflow: "" + }); + } + return w; + } +}); +BI.shortcut("bi.horizontal_sticky", BI.HorizontalStickyLayout); diff --git a/src/core/wrapper/sticky/sticky.vertical.js b/src/core/wrapper/sticky/sticky.vertical.js new file mode 100644 index 000000000..d99b8828e --- /dev/null +++ b/src/core/wrapper/sticky/sticky.vertical.js @@ -0,0 +1,38 @@ +/** + * 纵向黏性布局 + */ +BI.VerticalStickyLayout = BI.inherit(BI.FlexVerticalLayout, { + props: function () { + return BI.extend(BI.VerticalStickyLayout.superclass.props.apply(this, arguments), { + extraCls: "bi-v-sticky", + horizontalAlign: BI.HorizontalAlign.Stretch, + verticalAlign: BI.VerticalAlign.Stretch + }); + }, + + _addElement: function (i, item) { + var o = this.options; + var w = BI.VerticalStickyLayout.superclass._addElement.apply(this, arguments); + var rowSize = o.rowSize.length > 0 ? o.rowSize[i] : item.height >= 1 ? null : item.height; + if (o.rowSize.length > 0) { + if (item.height >= 1 && o.rowSize[i] >= 1 && o.rowSize[i] !== item.height) { + rowSize = null; + } + } + if (rowSize !== "fill") { + var firstItemFill = o.rowSize[0] === "fill" || o.items[0].height === "fill"; + w.element.css({ + position: "sticky", + zIndex: 1, + top: firstItemFill ? "" : 0, + bottom: firstItemFill ? 0 : "" + }); + } else { + w.element.css({ + overflow: "" + }); + } + return w; + } +}); +BI.shortcut("bi.vertical_sticky", BI.VerticalStickyLayout);