sublime-scroll 插件没有按预期滚动(iframe 事件捕获问题)

sublime-scroll plugin is not scrolling as expected (iframe event catching issue)

我想从 iframe 读取鼠标位置。我正在用这个实现来做:

$($("#sublime-scroll-iframe").contents()[0], window).find('body').bind("mousedown", 
    function(e) {
        console.log("x:" + (e.pageX) + ", y:" + e.pageY);
    }
);

我的工作示例:http://jsfiddle.net/s37e1ro0/1/ 但是

我无法使用 demux 的 sublime-scroll js 脚本。输出是 window 坐标或什么都不是。

Sublime-scroll 示例:http://django.is/ or you can download example files from https://github.com/demux/sublime-scroll

原因是,demux 的脚本实际上并不完全像 Sublime scroll 那样工作。例如。在 sublime 中,您会看到部分代码,然后单击该部分,sublime 会滚动到该部分代码。 demux 的脚本不是这种情况。单击页面的一部分不会滚动到页面的那一部分。它滚动到 window 和整个文档之间比率的位置。

我找不到它不起作用的原因。有人有什么主意吗? 或者如果有人想在没有鼠标坐标的情况下做到这一点?

            $(document).ready(function() {
                $.sublimeScroll({
                    top: 60, // px to top
                    bottom: 40, // px to bottom
                    scrollWidth: 200, // Width of scrollbar
                    removeElements: 'script',
                    fixedElements: 'header.top, footer.bottom',
                    contentWidth: 860, // Scroll viewport width
                    minWidth: 800 // Min width of window to display scroll
                });

                $("#sublime-scroll-overlay").css('display', 'none');

                var sscIfBody = $($("#sublime-scroll-iframe").contents()[0], window).find('body');
                var sscIfBar = $("#sublime-scroll-bar", sscIfBody);
                var sHold = false;
                var sDeltaY = 0;


                sscIfBody.bind("mousedown", function(e) {
                    window.scrollTo(e.pageX, e.pageY - window.innerHeight / 2);
                    e.preventDefault();
                });

                sscIfBar.bind('mousedown', function(e) {
                    sDeltaY = e.offsetY === undefined ? e.originalEvent.layerY : e.offsetY;
                    sHold = true;
                    e.stopPropagation();
                    e.preventDefault();
                });

                sscIfBody.bind("mouseup", function(e) {
                    sHold = false;
                });

                sscIfBody.bind("mousemove", function(e) {
                    if (sHold)
                        window.scrollTo(e.pageX, e.pageY - sDeltaY);
                }); 

            });

就是这样。现在它的工作方式与 Sublime 的滚动相同。享受吧!