【问题标题】:How to prevent page scroll when pasting?粘贴时如何防止页面滚动?
【发布时间】:2014-09-10 04:59:27
【问题描述】:

将数据粘贴到单元格时,页面会滚动到页面顶部或目标单元格的底部。

如何删除粘贴时的滚动?我希望页面完全不动。

【问题讨论】:

    标签: handsontable


    【解决方案1】:

    您可以应用以下代码的修复:

    $(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;
            }
        });
    
    });
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-27
      • 1970-01-01
      • 2016-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多