editormd.amd.js
function() {
            
            var _this            = this;
            var preview          = this.preview;
            var settings         = this.settings;
            var codeMirror       = this.codeMirror;
            var mouseOrTouch     = editormd.mouseOrTouch;
            
            if (!settings.syncScrolling) {
                return this;
            }
                
            var cmBindScroll = function() {    
                codeMirror.find(".CodeMirror-scroll").bind(mouseOrTouch("scroll", "touchmove"), function(event) {
                    var height    = $(this).height();
                    var scrollTop = $(this).scrollTop();                    
                    var percent   = (scrollTop / $(this)[0].scrollHeight);
                    
                    var tocHeight = 0;
                    
                    preview.find(".markdown-toc-list").each(function(){
                        tocHeight += $(this).height();
                    });
                    
                    var tocMenuHeight = preview.find(".editormd-toc-menu").height();
                    tocMenuHeight = (!tocMenuHeight) ? 0 : tocMenuHeight;

                    if (scrollTop === 0) 
                    {
                        preview.scrollTop(0);
                    } 
                    else if (scrollTop + height >= $(this)[0].scrollHeight - 16)
                    { 
                        preview.scrollTop(preview[0].scrollHeight);                        
                    } 
                    else
                    {
                        preview.scrollTop((preview[0].scrollHeight  + tocHeight + tocMenuHeight) * percent);
                    }
                    
                    $.proxy(settings.onscroll, _this)(event);
                });
            };

            var cmUnbindScroll = function() {
                codeMirror.find(".CodeMirror-scroll").unbind(mouseOrTouch("scroll", "touchmove"));
            };

            var previewBindScroll = function() {
                
                preview.bind(mouseOrTouch("scroll", "touchmove"), function(event) {
                    var height    = $(this).height();
                    var scrollTop = $(this).scrollTop();         
                    var percent   = (scrollTop / $(this)[0].scrollHeight);
                    var codeView  = codeMirror.find(".CodeMirror-scroll");

                    if(scrollTop === 0) 
                    {
                        codeView.scrollTop(0);
                    }
                    else if (scrollTop + height >= $(this)[0].scrollHeight)
                    {
                        codeView.scrollTop(codeView[0].scrollHeight);                        
                    }
                    else 
                    {
                        codeView.scrollTop(codeView[0].scrollHeight * percent);
                    }
                    
                    $.proxy(settings.onpreviewscroll, _this)(event);
                });

            };

            var previewUnbindScroll = function() {
                preview.unbind(mouseOrTouch("scroll", "touchmove"));
            }; 

			codeMirror.bind({
				mouseover  : cmBindScroll,
				mouseout   : cmUnbindScroll,
				touchstart : cmBindScroll,
				touchend   : cmUnbindScroll
			});
            
            if (settings.syncScrolling === "single") {
                return this;
            }
            
			preview.bind({
				mouseover  : previewBindScroll,
				mouseout   : previewUnbindScroll,
				touchstart : previewBindScroll,
				touchend   : previewUnbindScroll
			});

            return this;
        }
function() {
            
            var _this            = this;
            var preview          = this.preview;
            var settings         = this.settings;
            var codeMirror       = this.codeMirror;
            var mouseOrTouch     = editormd.mouseOrTouch;
            
            if (!settings.syncScrolling) {
                return this;
            }
                
            var cmBindScroll = function() {    
                codeMirror.find(".CodeMirror-scroll").bind(mouseOrTouch("scroll", "touchmove"), function(event) {
                    var height    = $(this).height();
                    var scrollTop = $(this).scrollTop();                    
                    var percent   = (scrollTop / $(this)[0].scrollHeight);
                    
                    var tocHeight = 0;
                    
                    preview.find(".markdown-toc-list").each(function(){
                        tocHeight += $(this).height();
                    });
                    
                    var tocMenuHeight = preview.find(".editormd-toc-menu").height();
                    tocMenuHeight = (!tocMenuHeight) ? 0 : tocMenuHeight;

                    if (scrollTop === 0) 
                    {
                        preview.scrollTop(0);
                    } 
                    else if (scrollTop + height >= $(this)[0].scrollHeight - 16)
                    { 
                        preview.scrollTop(preview[0].scrollHeight);                        
                    } 
                    else
                    {
                        preview.scrollTop((preview[0].scrollHeight  + tocHeight + tocMenuHeight) * percent);
                    }
                    
                    $.proxy(settings.onscroll, _this)(event);
                });
            };

            var cmUnbindScroll = function() {
                codeMirror.find(".CodeMirror-scroll").unbind(mouseOrTouch("scroll", "touchmove"));
            };

            var previewBindScroll = function() {
                
                preview.bind(mouseOrTouch("scroll", "touchmove"), function(event) {
                    var height    = $(this).height();
                    var scrollTop = $(this).scrollTop();         
                    var percent   = (scrollTop / $(this)[0].scrollHeight);
                    var codeView  = codeMirror.find(".CodeMirror-scroll");

                    if(scrollTop === 0) 
                    {
                        codeView.scrollTop(0);
                    }
                    else if (scrollTop + height >= $(this)[0].scrollHeight)
                    {
                        codeView.scrollTop(codeView[0].scrollHeight);                        
                    }
                    else 
                    {
                        codeView.scrollTop(codeView[0].scrollHeight * percent);
                    }
                    
                    $.proxy(settings.onpreviewscroll, _this)(event);
                });

            };

            var previewUnbindScroll = function() {
                preview.unbind(mouseOrTouch("scroll", "touchmove"));
            }; 

			codeMirror.bind({
				mouseover  : cmBindScroll,
				mouseout   : cmUnbindScroll,
				touchstart : cmBindScroll,
				touchend   : cmUnbindScroll
			});
            
            if (settings.syncScrolling === "single") {
                return this;
            }
            
			preview.bind({
				mouseover  : previewBindScroll,
				mouseout   : previewUnbindScroll,
				touchstart : previewBindScroll,
				touchend   : previewUnbindScroll
			});

            return this;
        }
function ( ) { var _this = this ; var preview = this . preview ; var settings = this . settings ; var codeMirror = this . codeMirror ; var mouseOrTouch = editormd . mouseOrTouch ; if ( ! settings . syncScrolling ) { return this ; } var cmBindScroll = function ( ) { codeMirror . find ( ".CodeMirror-scroll" ) . bind ( mouseOrTouch ( "scroll" , "touchmove" ) , function ( event ) { var height = $ ( this ) . height ( ) ; var scrollTop = $ ( this ) . scrollTop ( ) ; var percent = ( scrollTop / $ ( this ) [ 0 ] . scrollHeight ) ; var tocHeight = 0 ; preview . find ( ".markdown-toc-list" ) . each ( function ( ) { tocHeight += $ ( this ) . height ( ) ; } ) ; var tocMenuHeight = preview . find ( ".editormd-toc-menu" ) . height ( ) ; tocMenuHeight = ( ! tocMenuHeight ) ? 0 : tocMenuHeight ; if ( scrollTop === 0 ) { preview . scrollTop ( 0 ) ; } else if ( scrollTop + height >= $ ( this ) [ 0 ] . scrollHeight - 16 ) { preview . scrollTop ( preview [ 0 ] . scrollHeight ) ; } else { preview . scrollTop ( ( preview [ 0 ] . scrollHeight + tocHeight + tocMenuHeight ) * percent ) ; } $ . proxy ( settings . onscroll , _this ) ( event ) ; } ) ; } ; var cmUnbindScroll = function ( ) { codeMirror . find ( ".CodeMirror-scroll" ) . unbind ( mouseOrTouch ( "scroll" , "touchmove" ) ) ; } ; var previewBindScroll = function ( ) { preview . bind ( mouseOrTouch ( "scroll" , "touchmove" ) , function ( event ) { var height = $ ( this ) . height ( ) ; var scrollTop = $ ( this ) . scrollTop ( ) ; var percent = ( scrollTop / $ ( this ) [ 0 ] . scrollHeight ) ; var codeView = codeMirror . find ( ".CodeMirror-scroll" ) ; if ( scrollTop === 0 ) { codeView . scrollTop ( 0 ) ; } else if ( scrollTop + height >= $ ( this ) [ 0 ] . scrollHeight ) { codeView . scrollTop ( codeView [ 0 ] . scrollHeight ) ; } else { codeView . scrollTop ( codeView [ 0 ] . scrollHeight * percent ) ; } $ . proxy ( settings . onpreviewscroll , _this ) ( event ) ; } ) ; } ; var previewUnbindScroll = function ( ) { preview . unbind ( mouseOrTouch ( "scroll" , "touchmove" ) ) ; } ; codeMirror . bind ( { mouseover : cmBindScroll , mouseout : cmUnbindScroll , touchstart : cmBindScroll , touchend : cmUnbindScroll } ) ; if ( settings . syncScrolling === "single" ) { return this ; } preview . bind ( { mouseover : previewBindScroll , mouseout : previewUnbindScroll , touchstart : previewBindScroll , touchend : previewUnbindScroll } ) ; return this ; }
绑定同步滚动

@returns {editormd} return this
绑定同步滚动