Select Cells On A Table By Dragging

前端 未结 3 1938
一生所求
一生所求 2020-11-28 20:48

I was looking at this question and saw the reference to the iPhone game where you drag across the screen selecting letters as you go.

I was curious to see an implime

3条回答
  •  再見小時候
    2020-11-28 21:15

    Here's a working prototype: http://jsfiddle.net/few5E/ Using jQuery for DOM hooking, but could easily be implemented with another framework.

    Update: http://jsfiddle.net/Brv6J/ a slightly different version - the highlighted state will only change when you release and click again.

    Update 2: http://jsfiddle.net/Brv6J/3/ - binding onselectstart so that text is not selected in IE.

    A few relevant facts:

    • The mousedown event of the table cells is hooked to track the actual click. This event is stopped, so that text selection is hindered. Also binding ontextselect for the same effect in IE.
    • The mouseover event will toggle the highlighted class for the cell
    • The mouseout event is hooked on document. This is to ensure that it always runs. If the mouseup event was hooked on the table cell, it would not trigger if you released the mouse key with the mouse outside of the table. This state is tracked in isMouseDown.

    Full source code for reference:

    
    
    
      
      
      
    
    
      
    a b c
    d e f
    g h i

提交回复
热议问题