If you dont try to calculate the remaining %
then it seems to work as you expect
let colors = ["#ffd0d2","#fffdd0","#d0fffd","#d0d2ff"]; $(".main").children('section').each(function(){ let firstGradient = randomNumber(10,90); $(this).css( "background", "linear-gradient(141deg, "+colors[randomNumber(0,4)]+" "+firstGradient+"%, "+colors[randomNumber(0,4)] + ")" ); }); function randomNumber(min,max){ return Math.floor((Math.random() * max) + min); }
section{ display:block; height:200px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="main"> <section></section> <section></section> <section></section> </div>
Related Posts:
- How do you use the ? : (conditional) operator in JavaScript?
- Generate unique random numbers between 1 and 100
- W3TotalCache and Javascript — what should go where, when?
- How would I create the same popup in css and javascript as the one in contact button on the site https://www.sublimotionibiza.com/es/main.html [closed]
- uncaught TypeError: Cannot read properties of null (reading ‘classList’) custom plugin
- How do I minify a plugins CSS/JS code?
- Custom Plugin scripts from admin working in frontend
- Combine CSS Files without plugin
- How to sort posts by active category in WordPress?
- Type character in name and make it invisble
- Button doesn’t work in the profile panel
- WordPress Rest Api access the header and extract stylesheets URL
- Invert porfolio item order
- Image modification
- How to make a function to play only on the home page?
- Embed widget from external source (Zendesk)
- Hide Tab Titles from Tabs Block
- Add other class content with reference class value
- custom email validation using javascript api with elementor pro and code snippets
- How can I hide this custom slider while Elementor editing window is open?
- Overriding inline !important CSS with Javscript code snippet with media query
- broken internal JavaScript and CSS files
- Landing Page with HTML CSS JS and Images on wordpress
- How do I integrate vanilla Javascript to a wordpress website?
- How to make wocommerce shop products same heigt
- Getting and setting CSS variables with JQuery in WordPress backend fails
- Change hover to onclick on menu
- Unable to use Datepicker in a table when inserting a row
- Google CSE Malfunctions via Chrome/Safari on Mobile When Clicking on Either Search Icon/Menu Icon. How to Make Google CSE Default Theme Search
- I have a lot of JavaScript erorrs after SSL someone can help me?
- WordPress Slider is not working
- How to properly hide the div of an inline collapsible button?
- Change the version of default style.css in wordpress
- register dependency css and js inside a plugin class
- Getting click on item to open closest relevant element (popup) with jQuery
- How to create a mobile menu full screen overlay using Understraps Bootstrap 4 theme
- jQuery for Fade Preload Causes My Site Favicon to Disappear from Tab of Browser
- Web Developer Console: “Slow network is detected.” with fonts
- Bring Font Awesome icons inside menu A tags
- Hide CSS class only in single post pages
- Enqueue CSS and Script only if needeed
- Speeding up WordPress on a Local Network
- Caching of combined CSS and JS fails because of losing MIME types through combining by PHP
- custom field – changing an element or background of id div – different versions not working
- Target a specific container to style on WordPress storefront theme
- How to display javascript banner in website header?
- Site images are fixed in front of my site content [closed]
- How can I make menu items into two seperate buttons with different functions?
- How would I add this code to a single WordPress page?
- The placeholder text doesnt disappear
- Trouble with adding preloader to my home page index.html and index.js
- Speed issues because of CSS & JavaScript
- WordPress Admin Thickbox: Remove Margins/Padding
- Where to find the html for WordPress site? [closed]
- Converting HTML to WordPress theme: integrating pages function and using its text editor, conditional enqueuing
- WP Media Uploader modal conflicts with Bootstrap modal
- Best use adding user generated JS/CSS to a theme with a plugin
- Import HTML code that loads css and javascript into specific page
- How to set up php,javascript and css to allow for our finished product to be displayed within a page?
- Possible jquery / library conflict in plugin usage
- Trying to customize wordpress drop down categories
- How do i keep my current page menu highlighted on pagination?
- contact 7 plugin stops some pages from working properly
- How to implement a JavaScript and CSS file for my WordPress homepage?
- What can cause JavaScript and CSS files to be minified?
- How to reuse parts of WordPress site e.g. header, footer, part of header for multiple WordPress sites?
- Bootstrap 4 Optimization
- Move main menu to top of screen
- How to remove audio player styles added by mediaelement.js JavaScript?
- Element works, but not on wordpress site [duplicate]
- How to keep close a sub-menu under homepage? [closed]
- Making custom pages (with an example to explain the goal)
- Interactive maps in wordpress
- Eliminate Render blocking CSS?
- How to create and add js and css file when server is not on my PC?
- What is The Best Way to Make Parallax header effect for wordpress theme ?? pure CSS or using JavaScript? [closed]
- Changing when mobile menu is displayed
- Can I upload my HTML/CSS/Javascript game onto a WordPress page?
- How do I add JS and CSS to WP (Flatsome)
- “Plate” theme broken after update
- Particle.js not loading in WordPress Gutenberg
- This code works, but breaks the media uploader. How do I integrate it in a way that won’t?
- How can I only show one responsive menu on mobile devices?
- Active Navigation Class Based on URL on icon
- Modal pop-up HTML code works on other sites or HTML viewers but not in the custom HTML block within a wordpress page?
- How to remove pop up on website (css changes not visible)?
- how to add contact form 7 shortcode in javascript variable
- Sudden ERR_HTTP2_PROTOCOL_ERROR on every JS and CSS files loads
- How to optimise Text to HTML ratio for SEO by separating the HTML into multiple files?
- Override theme hamburger menu to work without javascript (noscript)
- hide specific css and js files in specific page wordpress with id or without?
- Separate typography controls for titles and meta in a custom block?
- opening and closing elementor-widget-container
- unable to find the document body in user-edit admin using javascript or CSS
- difference between code for admin, user facing (css, js)
- Identify and style the paragraph beginning w/o a class: based on a combination of common characters (CSS, JS)
- How do I remove/hide embed excerpts from posts
- Embed dynamic media query in a Gutenberg block
- Block style variations not enqueued for blocks inside HTML code dynamically rendered via JS
- How to resolve Multisite Speed issues