Jump to content

Background Color Change

Recommended Posts

  • Replies 4
  • Views 828
  • Created
  • Last Reply

Top Posters In This Topic

jQuery, see instructions in my signature for setting this up.

$(document).ready(function() {
  var col = ["#FFCCCC", "#CCAFFF", "#A6BEFF", "#99FFFF", "#D5CCBB", "#99FF99", "#FFFF99", "#FFCC99", "#CCCCCC"];
  var i = 0;
  changeColor();

  function changeColor() {
    $('body').attr('style', 'background-color: ' + col[i] + '');
    if (i < 8) {
      i++;
    } else {
      i = 0;
    }
    setTimeout(changeColor, 5000);
  }
});

 

Link to comment
  • 1 year later...
  • 3 weeks later...
19 hours ago, Fordham said:

Hi,

I would like to get this to work... I can't find any instructions in your signature. Apologies if i'm not looking in the right place. 

Thanks!

G

Add the code to Settings > Advanced > Code Injection > Footer

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
  $(document).ready(function() {
  var col = ["#FFCCCC", "#CCAFFF", "#A6BEFF", "#99FFFF", "#D5CCBB", "#99FF99", "#FFFF99", "#FFCC99", "#CCCCCC"];
  var i = 0;
  changeColor();

  function changeColor() {
    $('body').attr('style', 'background-color: ' + col[i] + '');
    if (i < 8) {
      i++;
    } else {
      i = 0;
    }
    setTimeout(changeColor, 5000);
  }
});
</script>

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.