Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>@apaul34208 pretty much hit the nail on the head there... I created an example for you based on the same principle so you can see it working.</p> <p><strong>HTML:</strong></p> <pre><code>&lt;header id="masthead" class="site-header" role="banner"&gt; &lt;div class="randomheader"&gt; &lt;div class="image"&gt;&lt;img src="" /&gt;&lt;/div&gt; &lt;span class="caption"&gt;&lt;/span&gt; &lt;/div&gt; &lt;nav id="site-navigation" class="main-navigation" role="navigation"&gt; nav here &lt;/nav&gt; &lt;/header&gt; </code></pre> <p><strong>CSS:</strong></p> <pre><code>.randomheader .image { position: relative; height: 0; /* This percentage needs to be calculated using the aspect ratio of your image. Type your image width and height in this tool to get the aspect ration of your image: http://andrew.hedges.name/experiments/aspect_ratio/ In this example the Google logo was 55:19 and to get the percentage you divide 19 by 55 = 0.3454 */ padding-bottom: 34.54%; } .randomheader img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; } .randomheader .caption { display: block; min-height: 1em; } .randomheader img, .randomheader .caption { opacity: 0; } </code></pre> <p><strong>jQuery:</strong></p> <pre><code>(function($) { $.fn.extend({ randomImage: function(config) { var defaults = {}, config = $.extend({}, defaults, config); return this.each(function() { var randNum = Math.floor(Math.random()*config.myImages.length), image = config.myImages[randNum], caption = config.myCaptions[randNum], path = config.path + image, $container = $(this), $image = $container.find('img'), $caption = $container.find('.caption'); // preload image before adding // to DOM and fading it in $image.attr({ src: path, alt: image }).load(function() { $caption.html(caption); $image.add($caption).animate({ opacity: 1 }, 'slow'); }); }); } }); }(jQuery)); // on DOM ready, // start 'er up jQuery(function($) { $('.randomheader').randomImage({ myImages: ['logo4w.png'], myCaptions: ['Google logo'], path: 'https://www.google.co.uk/images/srpr/' }); }); </code></pre> <p><strong><a href="http://jsfiddle.net/setEG/2/" rel="noreferrer">JSFiddle Demo</a></strong></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