Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>window.resize</code> is the correct event but it doesn't fire on page-load. You can however just add <code>.trigger('resize')</code> to your code to make it fire on page-load:</p> <pre><code>$(window).bind('resize', function(){ var containerSize = $('.container').width(), textPercentage = 0.17391304347826086956521739130435, /* 40/230 */ textRatio = containerSize * textPercentage, textEms = textRatio / 14; $('.container h3').css(fontSize, textEms+"em"); }).trigger('resize'); </code></pre> <p>You are going to want to run this code after <code>document.ready</code> to make sure the width you are getting for the container is correct. You could also place this code at the bottom of your HTML document (which you should do with or without the <code>document.ready</code> event handler) which will make sure the elements are available when you run this code:</p> <pre><code>//wait for `document.ready` to fire $(function () { //cache the .container and H3 elements var $container = $('.container'), $h3 = $container.find('h3'); //bind event handler to `window.resize` $(window).bind('resize', function(){ //get the width of the container var containerSize = $container.width(), textPercentage = 0.17391304347826086956521739130435, /* 40/230 */ textRatio = containerSize * textPercentage, textEms = textRatio / 14; $h3.css('fontSize', textEms+"em"); }).trigger('resize'); }); </code></pre> <p>Notice that I cached the <code>H3</code> element(s) so it/then don't have to be selected every <code>resize</code> event, because when you actually re-size your browser there are tons of these events that fire.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload