ใช้ฟังก์ชัน getBBox() และเพิ่มคำทีละคำในวัตถุข้อความ เมื่อมันกว้างเกินไป คุณต้องเพิ่มการป้อนบรรทัด
var a = Raphael(500, 500); var b = a.text(100, 100).attr('text-anchor', 'start'); var maxWidth = 100; var content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis nec semper mauris. Sed gravida augue feugiat nulla ultrices efficitur. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed sit amet lobortis eros, et lobortis diam. Aenean arcu velit, condimentum eu lacus in, dignissim bibendum odio. Mauris ultricies nunc et lorem bibendum dignissim. Ut porttitor purus vitae diam efficitur ultrices. Integer dignissim efficitur lorem, non vehicula diam scelerisque at "; var w = content.split(" "); var tempText = ""; for (var i = 0; i < w.length; i++) { b.attr("text", tempText + " " + words[i]); if (b.getBBox().width > maxWidth) { tempText += "\n" + words[i]; } else { tempText += " " + words[i]; } } b.attr("text", tempText.substring(1));