SVG textpath, determine when text goes beyond the path

前端 未结 3 522
有刺的猬
有刺的猬 2020-12-10 17:25

I have got the below code to display text along a path. I am planning to make sort of dynamic where I can just type in what i want and it displays it along the path. Haven\'

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-10 18:13

    You can query the computed lengths of the string that should go on the path, and the length of the path. Then compare the two, if the string length is longer than the path length then text will fall off the path.

    You can also use the knowledge of the path length to squeeze the string to fit, like this:

    
        
          
        
        
            
                
                    The quick brown fox jumps over the lazy dog                
                
            
            
        
    
    

    Here's an example where the string length is manipulated by decreasing the font-size:

    
        
          
        
        
            
                
                    The quick brown fox jumps over the lazy dog
                
            
            
        
        
    
    

提交回复
热议问题