Mark Wong
Posts: 0
Joined: Sat Feb 14, 2015 7:47 am

Calling JS to change the font size according to the screen size

Not able to change the size of the label on a list item (which mapped to the response of the list service) according to the screen size by calling JS when page load.
However when I preview the app and inspect the elements of the label and change the size Image

I've created a new Javascript for the app:
(from https://getsatisfaction.com/apperyio/...)
//This function will be used to add some css rule to the page.
function addCSSRule(sheet, selector, rules, index) {
if("insertRule" in sheet) {
sheet.insertRule(selector + "{" + rules + "}", index);
}
else if("addRule" in sheet) {
sheet.addRule(selector, rules, index);
}
}

When the page load, call JS:
addCSSRule(document.styleSheets[0], '.Chat_Screen_Label', "font-size: 40px;");

Mark Wong
Posts: 0
Joined: Sat Feb 14, 2015 7:47 am

Calling JS to change the font size according to the screen size

Is this code better?
Rather than doing something like:
codevar documentHeight = jQuery("body").height();
if(documentHeight < 350)/code and then call the JS to change the font.
(I'm not available to open my project with this computer so I can't test this code now.)
code
var documentHeight = jQuery(document)&#46;height();
alert(documentHeight);
var goalHeight = (documentHeight)*(35)/100;
var fontsize = Math&#46;ceil(goalHeight/10);
&#47;&#47;For example divided by 10
alert(goalHeight);
$("#Label")&#46;attr('style', 'font-size:'+fontsize+'px !important');
/code
is there anything wrong?

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Calling JS to change the font size according to the screen size

Mark,

Could you please clarify, do you try to use console.log in your function to check what "if" do you really use in your example and what really happens?

Mark Wong
Posts: 0
Joined: Sat Feb 14, 2015 7:47 am

Calling JS to change the font size according to the screen size

Never mind -.- I've already fixed the problem,
what I was saying in the question was
[Why I'm not able to use the JS code to change the font size!]
and I've change the code that in the comment and become like this:
code
var documentHeight = jQuery(document)&#46;height();
var fontsize = Math&#46;ceil(documentHeight/10);
&#47;&#47;For example divided by 10
Apperyio('Label')&#46;attr('style', 'font-size:'+fontsize+'px !important');
&#47;&#47;If Label is my target component name
/code
And its changing the font size according to the screen size!
Thank you for your help anyway :) Answered

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Calling JS to change the font size according to the screen size

Hi Mark - Thanks for this update.

Return to “Issues”