0

我已经为 textarea 应用了 enscroll 插件:

$('textarea[name="text_area_name"]').enscroll({
    showOnHover: true, 
    scrollIncrement: 20, 
    minScrollbarLength: 25, 
    verticalTrackClass: 'track3',
    verticalHandleClass: 'handle3'
});

现在的问题是空间和光标位置(左、上、右、下箭头)不适用于该文本区域。对于间距,我应用了以下代码,它可以完美地在文本区域书写期间添加间距:

$('#text_area_name').keydown(function(e) {
    var event = e.which || e.keyCode;

    // Handle Space button       
    if (event === 32) {
        var data = $(this).val();
        data += " ";
        $(this).val(data);
    }
});

CSS

textarea{
    width: 190px !important;
    height: 50px;
    resize: none;
    margin: 10px 0 0 0;
    border-radius: 5px;
    box-shadow: none;
    padding:10px;
    background-color: #EAEAEA;
}

但我不知道如何应用箭头键码并改变光标的位置。谁能指导我实现这一目标?

更新:我注意到当我点击 textarea 并按下 up 和 down 键时动态生成的滚动会移动,然后我认为 enscroll 插件有问题,但我不确定。

4

1 回答 1

0

I don't know if it's Right or Not but i have changed the part of the core enscroll plugin and it's work for me :

keyHandler = function( event ) {
    var $this = $( this ),
        data = $this.data( 'enscroll' ),
        scrollIncrement;

    // don't handle events that have just bubbled up
    if ( event.target === this && data ) {
        scrollIncrement = data.settings.scrollIncrement;

        switch( event.keyCode ) {
            /*case 32: // space*/
            case 34: // page down
                scrollVertical( this, $this.height() );
                return false;
            case 33: // page up
                scrollVertical( this, -$this.height() );
                return false;
            case 35: // end
                scrollVertical( this, this.scrollHeight );
                return false;
            case 36: // home
                scrollVertical( this, -this.scrollHeight );
                return false;
            /*case 37: // left
                scrollHorizontal( this, -scrollIncrement );
                return false;
            case 38: // up
                scrollVertical( this, -scrollIncrement );
                return false;
            case 39: // right
                scrollHorizontal( this, scrollIncrement );
                return false;
            case 40: // down
                scrollVertical( this, scrollIncrement );
                return false;
                                    */
        }
        return true;
    }
}

this is the function that handles all the keys that i was struggled for( space -> 32 and 37 to 40 direction keys ), i just disable the associated keys.

And now its working for me ;)

But is there a way to disable these keys outside from core files? with using of plugin reference etc.?

于 2013-09-30T06:35:44.930 回答