How to use this square cursor in a HTML input field?

后端 未结 6 957
南旧
南旧 2020-11-29 05:13

How can I use this square cursor ( image below ) in the input tags ?

\"C:\\WIKIPEDIA\"

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 06:00

    Sample

    Sample

    I've changed how it works, and it seems to solve a few issues :)

    • Accepts any text a normal input can
    • Backspace works
    • Theoretically can support pasting text

    Usual caveats apply still, most notably the inability to visually see where the caret is.

    I'd think long and hard whether this solution is worth implementing, based on its drawbacks and usability issues.

    $(function() {
      var cursor;
      $('#cmd').click(function() {
        $('input').focus();
        cursor = window.setInterval(function() {
          if ($('#cursor').css('visibility') === 'visible') {
            $('#cursor').css({
              visibility: 'hidden'
            });
          } else {
            $('#cursor').css({
              visibility: 'visible'
            });
          }
        }, 500);
    
      });
    
      $('input').keyup(function() {
        $('#cmd span').text($(this).val());
      });
    
      $('input').blur(function() {
        clearInterval(cursor);
        $('#cursor').css({
          visibility: 'visible'
        });
      });
    });
    #cmd {
      font-family: courier;
      font-size: 14px;
      background: black;
      color: #21f838;
      padding: 5px;
      overflow: hidden;
    }
    #cmd span {
      float: left;
      padding-left: 3px;
      white-space: pre;
    }
    #cursor {
      float: left;
      width: 5px;
      height: 14px;
      background: #21f838;
    }
    input {
      width: 0;
      height: 0;
      opacity: 0;
    }
    
    

提交回复
热议问题