浮动元素固定位置

当浮动元素(图片或是自定义浮动元素)的 fixedPosition 为 true 时,浮动元素的位置将不会因滚动,行列可见性,改变行列高宽或移动行列而改变。

你可以通过调用 fixedPosition 方法来设置是否在固定位置显示浮动元素。 当 fixedPosition 为 true 时, dynamicMove 和 dynamicSize 将被忽略。 当 fixedPosition 为 true 时, 浮动元素可以被用户拖拽移动和改变大小。 当 fixedPosition 为 true 时, 浮动元素的以下属性依然会正常工作。 position height width startRow startRowOffset startColumn startColumnOffset endRow endRowOffset endColumn endColumnOffset
window.onload = function () { var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss")); initSpread(spread); }; function initSpread(spread) { var sheet = spread.getSheet(0); sheet.setColumnWidth(0, 20); var content1 = document.createElement("div"); content1.style.backgroundColor = "gray"; content1.style.width = "100%"; content1.style.height = "100%"; content1.innerHTML = "Floating objects at fixed position."; var customFloatingObject1 = new GC.Spread.Sheets.FloatingObjects.FloatingObject("customFloatingObject1", 20, 20, 240, 20); customFloatingObject1.content(content1); customFloatingObject1.fixedPosition(true); sheet.floatingObjects.add(customFloatingObject1); var content2 = document.createElement("div"); content2.style.backgroundColor = "lightgray"; content2.style.width = "100%"; content2.style.height = "100%"; content2.innerHTML = "Normal floating objects."; var customFloatingObject2 = new GC.Spread.Sheets.FloatingObjects.FloatingObject("customFloatingObject2", 20, 280, 240, 20); customFloatingObject2.content(content2); sheet.floatingObjects.add(customFloatingObject2); };
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta name="spreadjs culture" content="zh-cn" /> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets-resources-zh/dist/gc.spread.sheets.resources.zh.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script> <script src="app.js" type="text/javascript"></script> <link rel="stylesheet" type="text/css" href="styles.css"> </head> <body> <div class="sample-tutorial"> <div id="ss" class="sample-spreadsheets"></div> <div class="options-container"> <p style=" padding:2px 10px;background-color:#F4F8EB;">Try resizing column A in the Spread component to see that the fixed floating objects do not move</p> </div> </div> </body> </html>
.sample-tutorial { position: relative; height: 100%; overflow: hidden; } .sample-spreadsheets { width: calc(100% - 280px); height: 100%; overflow: hidden; float: left; } .options-container { float: right; width: 280px; padding: 12px; height: 100%; box-sizing: border-box; background: #fbfbfb; overflow: auto; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }