你好,这个问题我这边重现了一下。
造成这个问题的原因是,由于Demo中是把单个单元格中的背景图进行了放大绘制,
而当滚动条滚动到目标单元格下方时,目标单元格并未被绘制,此时就会出现问题。
解决办法是添加滚动条事件,在事件中注册setTimeout,将sheet重绘即可。
setTimeout时间应控制在不影响视觉效果的情况下尽量长一些。
代码如下:
- function WaterMarkCellType() {
- this.typeName = "WaterMarkCellType"
- }
- WaterMarkCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();
- WaterMarkCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
- //Paints a cell on the canvas.
- var that = this;
- var background = style.backgroundImage;
- style.backgroundImage = undefined;
- GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
- GC.Spread.Sheets.CellTypes.Text.prototype.paint.call(that, ctx, undefined, x, y, w+100, h+100, {backgroundImage:background}, options);
- };
- $(document).ready(function () {
- var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
- var sheet = spread.getActiveSheet();
- sheet.getCell(3, 3).cellType(new WaterMarkCellType()).backgroundImage('https://www.grapecity.com.cn/images/metalsmith/home/logo_spjs.png')
- sheet.setArray(2, 2, [[1,2,3,4,5,6,],[1,2,3,4,5,6,],[1,2,3,4,5,6,],[1,2,3,4,5,6,],[1,2,3,4,5,6,],[1,2,3,4,5,6,]]);
- var setTimeoutId = null;
- sheet.bind(GC.Spread.Sheets.Events.TopRowChanged, function (s, e) {
- clearTimeout(setTimeoutId);
- // 这里的间隔时间,在不影响视觉效果的情况下尽可能长一点
- setTimeoutId = setTimeout(function(){
- e.sheet.repaint();
- }, 50);
- });
- });
复制代码 |