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
- Define a global variable in a JavaScript function
- How to change CSS using jQuery?
- What is the difference between React Native and React?
- Remove class using jQuery
- How can I scroll to an element using jQuery?
- Remove CSS class from element with JavaScript (no jQuery) [duplicate]
- What is the meaning of == $0 that is shown in inspect element of google chrome for the selected element [duplicate]
- Bootstrap Dropdown menu is not working
- How to generate a simple popup using jQuery
- CSS: background-color only inside the margin
- How to add a color overlay to a background image?
- Bootstrap Dropdown menu is not working
- Bootstrap Dropdown menu is not working
- What do curly braces in JavaScript mean?
- How do you Hover in ReactJS? – onMouseLeave not registered during fast hover over
- How to print HTML content on click of a button, but not the page?
- 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?
- Force div to be topmost element of any and all webpages
- “Uncaught TypeError: a.indexOf is not a function” error when opening new foundation project
- how to display a div triggered by onclick event
- jQuery scrollTop() method not working
- Set CSS property in JavaScript?
- JavaScript – Count Number of Visitor for Website
- Getting or changing CSS class property with Javascript using DOM style
- Bootstrap Collapse not Collapsing
- Cannot read property ‘style’ of undefined — Uncaught Type Error
- How to make HTML element resizable using pure Javascript?
- How do I clear the content of a div using JavaScript?
- WordPress how to remove blocksy theme price and put my own price
- How to add a custom CSS class to core blocks in Gutenberg editor?
- Any alternate TinyMCE4 themes / subthemes?
- How can I reduce the amount of files loaded/included per plugin?
- How to solve ‘Eliminate render-blocking JavaScript and CSS in above-the-fold’ content for multiple files?
- How do you use JavaScript to detect the homepage
- How do I add JavaScript that will execute on all my sites in Multisite?
- Collapsible button inside a ul list does work in jsfiddle but not in WP
- Relative path instead of absolute for wp_enqueue_script
- Handling URLs in WordPress application
- Combining multiple javascript and css files
- Can “ and “ tags be used in the HTML editor?
- W3 Total Cache: Load CSS asynchronously for better PageSpeed score? [closed]
- 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
- Can someone please tell me what is wrong with my plugin?
- How to integrate my HTML and javascript into my child theme
- Twenty fifteen theme – change responsive menu condition
- How does wp_enqueue_scripts work?
- 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?
- 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
- 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
- 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
- Possible jquery / library conflict in plugin usage
- 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?
- This code works, but breaks the media uploader. How do I integrate it in a way that won’t?
- Active Navigation Class Based on URL on icon
- How to remove pop up on website (css changes not visible)?
- How do I remove/hide embed excerpts from posts
- Hide or Show Read More Button by Content Area