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 to format a JavaScript date
- Failed to load resource: the server responded with a status of 404 (Not Found)
- Define a global variable in a JavaScript function
- Cross-Origin Read Blocking (CORB)
- What is the difference between React Native and React?
- Remove CSS class from element with JavaScript (no jQuery) [duplicate]
- Set cookie and get cookie with JavaScript
- What is the meaning of == $0 that is shown in inspect element of google chrome for the selected element [duplicate]
- Change Background color (css property) using Jquery
- How to generate a simple popup using jQuery
- CSS: background-color only inside the margin
- How to change css property using javascript
- JavaScript Loading Screen while page loads
- Completely disable scrolling of webpage
- How to add a color overlay to a background image?
- Bootstrap Dropdown menu is not working
- What do curly braces in JavaScript mean?
- How to add multiple classes to a ReactJS Component?
- Why is the jquery script not working?
- Change text on hover, then return to the previous text
- Textarea Auto height
- Mixed Content Page: requested an insecure stylesheet error
- How to change the background-color of jumbrotron?
- “Uncaught TypeError: a.indexOf is not a function” error when opening new foundation project
- how to display a div triggered by onclick event
- JavaScript – Count Number of Visitor for Website
- Getting or changing CSS class property with Javascript using DOM style
- How to create a hidden
in JavaScript?
- Bootstrap Collapse not Collapsing
- Cannot read property ‘style’ of undefined — Uncaught Type Error
- How to make div background color transparent in CSS
- How to make HTML element resizable using pure Javascript?
- How to set “style=display:none;” using jQuery’s attr method?
- WordPress Bootstrap Handburger Menu Wont Open
- How to add a custom CSS class to core blocks in Gutenberg editor?
- WordPress Admin Bar pushed Sticky Footer off the bottom of the page
- Any alternate TinyMCE4 themes / subthemes?
- How can I reduce the amount of files loaded/included per plugin?
- How to prevent loading of all plugin’s resources?
- How do you use JavaScript to detect the homepage
- Prevent CSS/JS loading when plugin is not used
- Collapsible button inside a ul list does work in jsfiddle but not in WP
- Handling URLs in WordPress application
- Combining multiple javascript and css files
- how to include javascript file and css file in wordpress
- Can “ and “ tags be used in the HTML editor?
- JavaScript added as link/stylesheet
- Eliminate render-blocking JavaScript and CSS in above-the-fold content
- how to add custom css and js on wordpress post editor directly without using .php file
- Incorrect MIME type for assets with Valet
- Twenty fifteen theme – change responsive menu condition
- Static page to one page- menu inactive items highlighted
- Radio buttons live refresh in the customizer
- How to get DEFER or ASYNC attribute to appear when I add a stylesheet with wp_enqueue_style from a plugin? [duplicate]
- How to properly Remove certain CSS / JS files from template
- Why is this jquery / java script code not working in mobile / in devices?
- Seperate functions.php for part of site
- how to prevent all css and javascripts files from loading
- Custom Plugin – CSS works, JS doesn’t
- trouble with page_id & highlighting current page
- wordpress admin plugin menu custom css
- How can I wrap all blog posts image with
- How to Change CSS Colors from Custom Plugin Settings Page
- Conditionally enqueue a stylesheet based off of a javascript click event
- White screen when attaching css to function.php
- WordPress theme resource won’t load over VPN
- How to Add a Read-only Textbox With Text in it That Has a Button to Copy it?
- Link to page with posts of specific type
- prevent HTML output if custom field is empty [closed]
- Is it OK combined wp-include js, jquery, css? [closed]
- WordPress getting css and script files from client machine rather than the server machine
- CSS/JS files in WordPress
- How do I override all stylesheets and scripts without a plugin
- 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]
- Custom Plugin scripts from admin working in frontend
- Combine CSS Files without plugin
- WordPress Rest Api access the header and extract stylesheets URL
- Hide Tab Titles from Tabs Block
- Add other class content with reference class value
- How do I integrate vanilla Javascript to a wordpress website?
- Change hover to onclick on menu
- WordPress Slider is not working
- How to properly hide the div of an inline collapsible button?
- 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
- Caching of combined CSS and JS fails because of losing MIME types through combining by PHP
- Target a specific container to style on WordPress storefront theme
- 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
- How to reuse parts of WordPress site e.g. header, footer, part of header for multiple WordPress sites?
- How to remove audio player styles added by mediaelement.js JavaScript?
- Element works, but not on wordpress site [duplicate]
- 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
- Active Navigation Class Based on URL on icon
- How to remove pop up on website (css changes not visible)?