如何在鼠标移动过程中使用鼠标按键进行鼠标定位(pageX,pageY)

时间:2016-09-22 12:15:33

标签: jquery

只有在按下鼠标按钮时才需要每次移动的实际鼠标位置。

我使用了以下内容:

var time, click= $( '#foo li' );
    click.mousedown(function(e){
                time= setInterval(function(){
                    $( '#foo li' ).mousemove(function( event ) {
                        var msg = "Handler for .mousemove() called at ";
                        msg += event.pageX + ", " + event.pageY;
                        $( ".output" ).empty();
                        $( ".output' ).append( msg );
                    });
            }, 500);
            return false;
        });

        $(document).mouseup(function(e){
            clearInterval(time);
            $(window).unbind( 'mousemove');
            return false;
        });

工作正常:每个位置都会打印在'输出中。但是mouseup Event不会停止mousemove功能。可能是什么问题?

更新:

对不起,我刚开始......

我试过这种方式,它工作正常。有没有更好的方法来告诉我......

var down = false;
$('#foo').mousedown(function(){
    down = true;
});

$(document).mouseup(function(){
    down = false;
})

$('#foo').mousemove(function(e){
    if(down == false) return;
      $('.output').empty();
      $('.output').append(e.pageX +' & ' + e.pageY);
});

1 个答案:

答案 0 :(得分:0)

试试这个:

/**
 * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
 * For licensing, see LICENSE.md or http://ckeditor.com/license
 */

CKEDITOR.editorConfig = function( config ) {
    // Define changes to default configuration here.
    // For complete reference see:
    // http://docs.ckeditor.com/#!/api/CKEDITOR.config

    // The toolbar groups arrangement, optimized for two toolbar rows.
    config.toolbarGroups = [
        { name: 'clipboard',   groups: [ 'clipboard', 'undo' ] },
        { name: 'editing',     groups: [ 'find', 'selection', 'spellchecker' ] },
        { name: 'links' },
        { name: 'insert' },
        { name: 'forms' },
        { name: 'tools' },
        { name: 'document',    groups: [ 'mode', 'document', 'doctools' ] },
        { name: 'others' },
        '/',
        { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
        { name: 'paragraph',   groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ] },
        { name: 'styles' },
        { name: 'colors' },
        { name: 'about' }
    ];

    // Remove some buttons provided by the standard plugins, which are
    // not needed in the Standard(s) toolbar.
    config.removeButtons = 'Underline,Subscript,Superscript';

    // Set the most common block elements.
    config.format_tags = 'p;h1;h2;h3;pre';

    // Simplify the dialog windows.
    config.removeDialogTabs = 'image:advanced;link:advanced';

    config.autoParagraph = false;

    config.basicEntities = false;
    config.AllowedContent = "br[clear]";


};
var click= $( '#foo li' );
click.mousedown(function(e){
  $( '#foo li' ).mousemove(function( event ) {
    var msg = "Handler for .mousemove() called at ";
    msg += event.pageX + ", " + event.pageY;
    $( '.output' ).empty();
    $( '.output' ).append( msg );
  });
});

$(document).mouseup(function(e){
  $( '#foo li' ).unbind( 'mousemove');
});