0

In a GWT web application, I want to give the opportunity to my users to decrease or increase font size in the current page.

Is it possible, in GWT, to do this, if the user click on + button:

body { font-size: 150%; }

And to do this, if the user click on - button:

body { font-size: 50%; }

Thanks!

superscral
  • 480
  • 1
  • 11
  • 33

2 Answers2

1

This works for a CSS inline solution. Replace CLASSNAMEHERE to suit your needs, or pass it as a parameter of the function.

private static native void changeFontSize(int inc)/*-{
        {
            var p = $doc.getElementsByClassName('CLASSNAMEHERE');
            for (n = 0; n < p.length; n++) {
                if (p[n].style.fontSize) {
                    var size = parseInt(p[n].style.fontSize.replace("px", ""));
                } else {
                    var size = 11;
                }
                p[n].style.fontSize = size + inc + 'px';
            }
        }
    }-*/;
Jean-Michel Garcia
  • 2,359
  • 2
  • 23
  • 44
0

Please try following:

Document.get().setStyleAttribute("font-size", "150%");

If you need to modify styles of particular style classes, then you should query them first somehow. (with native JS or http://code.google.com/p/gwtquery/ for example) Then iterate them and modify style attributes

DOM.setStyleAttribute(someGwtElement.getElement(), "font-size", "150%");
udalmik
  • 7,838
  • 26
  • 40