jquery - How to achieve superscript on rapahel text -
how achieve superscript on rapahel text when user types in textarea getting value , updating raphael text using rapaheltext.attr({text:textarea.value}) if types 2^n want 2ⁿ on rapahel text wise alphabets 2^x ,2^o etc
ok, did research adding superscripts , subscripts raphael text...but no luck. raphael.text() gets string type not interpret html string.
so, have got different solution works fine. @ demo
in demo when enter text without ^ , ^, can see works. of course simple example, need adjust code liking or according application.
var paper = new raphael("canvas"); var r = paper.rect(75,10,150,80,5).attr({fill:'yellow'}); $('#btn').click(function() { var text = document.getelementbyid('ttt').value; var pos = text.indexof('^'); if (text.indexof('^') > 0) { // want create superscript var = text.substring(0, pos); var b = text.substring(pos + 1); document.getelementbyid('text').innerhtml = + '<sup>' + b + '</sup>'; } else { document.getelementbyid('text').innerhtml = text; } }); what did create empty div absolute positioning , set it's position middle of i.e. raphael.rect(). purpose of div act raphael.text().
this gives ability use innerhtml , set text inside div using html's <sup> , <sub> tags.
good luck
Comments
Post a Comment