How to have transparent fonts except for the 'text-caret' in a textarea?

后端 未结 4 810
难免孤独
难免孤独 2021-02-13 19:36

I have a simple textarea and I need to make transparent letters while allowing the text-caret to be visible. When I apply the following rules then I get invisible caret:

4条回答
  •  轮回少年
    2021-02-13 20:12

    Time to throw my $0.02 in.

    This is an answer to the question, as I understood it, that works, it's quick and dirty, so feel free to make suggestions. This code is untested, but I did create a working fiddle here: http://jsfiddle.net/66RXc/

    
    
    Testing
    
    
    
    
    
    
    

    The way I approached it was every time a character is typed in textarea "test", copy it over to a hidden text box, and replace all the characters in "test" except ^ with spaces. The characters are hidden, and the carat is still there. The full text is still in the other box. You could use display:hidden instead of display:block to hide it.

    This isn't exactly the best implementation in the world, just something I did quickly. You have to type kind of slow (~15-20 WPM) for it to work.

提交回复
热议问题