Vertical Split Background Colors
General Discussion
4
Posts
2
Posters
1.6k
Views
1
Watching
-
Hey there!
I have two questions:- How can I make the background color of a page two colors split vertically (ex: left half red, right half blue, split in the middle)?
- Is there any way I could also integrate the random color script from this thread: http://laythemeforum.com/topic/674/random-color-background
So that every time you refresh the page, each half is a different color?
Thanks!
-
-
I would go for a background image.
-
That needs some coding. You are fit with jQuery?
Best!
Marius
-
-
- Okay, cool. That's what I did originally but I wasn't sure if it was maybe cleaner/faster to code it...
- I've just been learning when things come up. Not sure I can figure this one out on my own.
-
I did not do the whole thing but actually you just need to copy the code and use it again_
<script> var colors = ["#fff", '#000', '#f0f', '#0ff', '#00f', '#ff0', '#0f0'] Frontend.GlobalEvents.on("work", function(layoutObj, type, obj){ if(obj.slug == "frontpage"){ var ix = getRandomInt(0, colors.length); var color = colors[ix]; jQuery('.colors-1').css('background-color', color); } }); // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random // Returns a random integer between min (included) and max (excluded) // Using Math.round() will give you a non-uniform distribution! function getRandomInt(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min)) + min; } var colors2 = ["#fff", '#000', '#f0f', '#0ff', '#00f', '#ff0', '#0f0'] Frontend.GlobalEvents.on("work", function(layoutObj, type, obj){ if(obj.slug == "frontpage"){ var ix = getRandomInt2(0, colors2.length); var color = colors2[ix]; jQuery('.colors-2').css('background-color', color); } }); // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random // Returns a random integer between min (included) and max (excluded) // Using Math.round() will give you a non-uniform distribution! function getRandomInt2(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min)) + min; } </script>Then you make two divs:
<div class="colors-1">COLORS-1</div> <div class="colors-2">COLORS-2</div>This is a quick and dirty method and you might do some adjustments to get it work. But this is how you colud do it.
Otherwise use images.
Best!!
Marius
For 1on1 paid Lay Theme Coaching, contact: audrey@cyberslayers.work.
We also code custom websites or custom Lay features.
šæ Email us here: šæ
info@laytheme.com
Our Web Development company: 100k.studio
Want to tip me? https://www.paypal.com/paypalme/arminunruh
Before you post:
- When using a WordPress Cache plugin, disable it or clear your cache.
- Update Lay Theme and all Lay Theme Addons
- Disable all Plugins
- Go to Lay Options ā Custom CSS & HTML, click "Turn Off All Custom Code", click "Save Changes"
This often solves issues you might run into
When you post:
- Post a link to where the problem is
- Does the problem happen on Chrome, Firefox, Safari or iPhone or Android?
- If the problem is difficult to explain, post screenshots / link to a video to explain it
Online Users
Forgot your key, lost your files, need a previous Lay Theme or Addon version?
Go to www.laykeymanager.com