[removed] how can I tell if a is broken over 2 lines?

后端 未结 4 1417
攒了一身酷
攒了一身酷 2021-02-01 18:43

I display a bubble help for some short span elements. The bubbles are centered below that span and look great as long as the span isn\'t broken over two lines.

Looks goo

4条回答
  •  死守一世寂寞
    2021-02-01 19:10

    9000's comment is correct. The trick is having access to a that you know will be rendered on a single line. You can do that by wrapping the first word of your block in a span with a specific id, you could also use the last word or some other single word; there are cases where a single word will cross lines but the first word should be safe.

    Once you have something that is only on one line you can compare its height to the height of the that will get the tooltip. If the that is getting the tooltip is taller than the single-line then it has wrapped to multiple lines.

    Try this jsfiddle:

    http://jsfiddle.net/ambiguous/JbMhZ/1/

    Adjust the size of the right panes until the red text wraps but the green text doesn't. Then hit Run in the toolbar at the top and it should say this at the bottom of the Result pane:

    #has-break spans more than one line
    #no-break spans only one line
    

    I'm not exactly proud of this hack but it should work.

    I'm left wondering if a better positioning algorithm for your tooltip would be a better idea. Maybe pull the mouse coordinates out of the hover event and use that to position the tooltip rather than positioning it based on the .

提交回复
热议问题