简体   繁体   English

Handsontable-粘贴到单元格时禁用自动向上滚动

[英]Handsontable - Disable auto scroll up when pasting into a cell

When I paste into a cell which is nearing the top of the page in a handsontable table, the page automatically scrolls up to center the window on the cell. 当我粘贴到可动手操作表中靠近页面顶部的单元格中时,页面会自动向上滚动以将窗口置于单元格的中心。

I've tried to locate the code causing this in jquery.handsontable.full.js in the hopes of disabling it, but haven't been successful. 我试图在jquery.handsontable.full.js中找到导致此问题的代码,以希望将其禁用,但没有成功。

Some help would be greatly appreciated! 一些帮助将不胜感激!

I've been struggling with the same problem for the past weeks until today, I managed to fix it without editing the library. 在过去的几周里,直到现在,我一直在努力解决相同的问题,我设法在不编辑库的情况下解决了该问题。

Where I initialize the handsontable I added the following: 在初始化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;
        }
    });

});

This works for me at least, hope it helps you as well! 至少对我有用,希望对您也有帮助!

See the comment by wiwade on the issue. 参见wiwade 对此问题的评论

Perhaps its a hacky fix, but worked fine for me on google chrome Version 37.0.2062.120 (64-bit) 也许它是个漏洞修复程序,但在Google Chrome 37.0.2062.120版(64位)上对我来说效果很好

Change 更改

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

to

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

in copypaste.js, jquery.handsontable.full.js or jquery.handsontable.js 在copypaste.js,jquery.handsontable.full.js或jquery.handsontable.js中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM