【问题标题】:Handsontable - Disable auto scroll up when pasting into a cellHandsontable - 粘贴到单元格时禁用自动向上滚动
【发布时间】:2014-08-26 22:02:09
【问题描述】:

当我粘贴到一个靠近页面顶部的单元格中时,页面会自动向上滚动以使窗口居中在单元格上。

我试图在 jquery.handsontable.full.js 中找到导致此问题的代码,希望禁用它,但没有成功。

我们将不胜感激!

【问题讨论】:

    标签: javascript jquery scroll handsontable


    【解决方案1】:

    过去几周我一直在为同样的问题苦苦挣扎,直到今天,我设法在不编辑库的情况下解决了它。

    我在初始化handsontable的地方添加了以下内容:

    $(document).ready(function () {
        var position_Y_before = null;
    
        $(".handsontable").handsontable({
            //some code here for initializing the table and its functions
    
            //Then I added this callback function
            beforeKeyDown: function(e) {
                position_Y_before = window.pageYOffset || 0;
            };
    
        });
    
        //Here we prevent from scrolling to top of page after pasting to handsontable with cmd+v or ctrl+v
        $(window).scroll(function(){
            if(position_Y_before != null){
                window.scrollTo(0, position_Y_before);
                position_Y_before = null;
            }
        });
    
    });
    

    这至少对我有用,希望对你也有帮助!

    【讨论】:

      【解决方案2】:

      请参阅wiwade 的comment 讨论该问题。

      也许这是一个 hacky 修复,但在 google chrome 版本 37.0.2062.120(64 位)上对我来说效果很好

      改变

      style.top = '-10000px';
      style.left = '-10000px';
      

      到

      style.top = '0px';
      style.left = '0px';
      style.zIndex = '-99999';
      

      在 copypaste.js、jquery.handsontable.full.js 或 jquery.handsontable.js 中

      【讨论】:

        猜你喜欢
        • 2015-02-07
        • 2018-03-29
        • 1970-01-01
        • 2011-10-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多