Using jQuery to create radial-gradients with the background-css feature

I'm a newcomer to this online community and English is not my first language. Despite that, I will do my utmost to clearly explain the issue at hand.

Recently, I utilized the .css function in jQuery to create a design element successfully. However, I encountered difficulties when trying to implement the 'radial-gradient...' background feature. Unfortunately, I lack knowledge of the correct syntax for this particular feature.

My initial attempt was as follows:

'background-image': 'radial-gradient(closest corner at 35% 35%, rgba(255, 255, 255, 0.5) 5%, rgba('+ color +','+ opacity +') 20%)'

Regrettably, the above code did not produce the expected outcome. Upon inspecting Firebug, it became apparent that the background-image attribute was not displayed.

The entirety of my jQuery function appears below:

function spots(spotCount) {
    var spotCount = spotCount;
    for (i = 0; i < spotCount; i++) {
        var opacity = '0.' + randomNumber(2, 5);
        var color = randomNumber(0, 255) + ',' + randomNumber(0, 255) + ',' + randomNumber(0, 255);
        var size = randomNumber(20, 30);
        var top = randomNumber(0, (($('#wrap')).height() - size));
        var left = randomNumber(-100, (980 - size + 100));
        $('<div id="spot' + i + '"></div>').appendTo('#header .width');
        $('#spot' + i).css({
            position: 'absolute',
            top: top + 'px',
            left: left + 'px',
            'z-index': '-100',
            width: size + 'px',
            height: size + 'px',
            'border-radius': size + 'px',
            border: 'rgba(' + color + ',' + opacity + ') solid 1px',
            background: 'radial-gradient (closest-corner at 35% 35%, rgba(255,255,255,'+ opacity +'),rgba(' + color + ',' + opacity + '))'
        });
    }

Additionally, I require the -webkit- syntax compatible with Safari 5.1.

If anyone can provide me with the correct syntax, I would be extremely grateful.

Thank you in advance for your assistance.

You can view the jsfiddle link here: http://jsfiddle.net/g99et0yq/1/

Upon visiting the link, you'll notice that the spots are displaying incorrectly.

Answer №1

I successfully solved the issue on my own!

Check out my solution on jsfiddle:http://jsfiddle.net/g99et0yq/10/

Here is the HTML code snippet:

<div id="header" style="height:300px;">
    <div class="width" style="width:300px;">

    </div>
</div>

This is the JavaScript code I used:

function randomNumber(minimal, maximal)
{
    return(minimal + parseInt(Math.random() * (maximal - minimal + 1)));
}

function spots(spotCount) {
    var spotCount = spotCount;
    for (i = 0; i < spotCount; i++) {
        var opacity = '0.' + randomNumber(2, 5);
        var color = randomNumber(0, 255) + ',' + randomNumber(0, 255) + ',' + randomNumber(0, 255);
        var size = randomNumber(20, 30);
        var top = randomNumber(0, (($('#header')).height() - size));
        var left = randomNumber(-100, (980 - size + 100));
        $('<div id="spot' + i + '"></div>').appendTo('#header .width');
        
        $('#spot' + i).css({
            position: 'absolute',
            top: top + 'px',
            left: left + 'px',
            'z-index': '-100',
            width: size + 'px',
            height: size + 'px',
            'border-radius': size + 'px',
            border: 'none',
            'background-color':  'rgba('+ color +','+ opacity +')'
        }).addClass('spotgloss');
    }
}

spots(10);

And this is the CSS styling I applied:

.spotgloss {
    background: -webkit-radial-gradient(35% 35%, circle, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 35%); 
    background: radial-gradient(circle at 35% 35%, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 35%);
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Identifying PHP post/get variables with jQuery

I am working on a PHP project where I have a form that sends a variable to the same page. I am looking to create a jQuery script that will show or hide a specific div based on the value sent by the form. Here is the form code I have in my PHP file: < ...

Troublesome situation arising from CSS floats overlapping div elements

It's strange how this issue always occurs when using floats. This is what my div (samle) looks like: <div class="main> <div class="inn_div">&nbsp</div> </div> Here is my stylesheet: .main{ width:250px; border:1px ...

The calculator I designed using HTML, CSS, and JavaScript is experiencing difficulty adjusting to various screen sizes

I recently built a calculator using HTML, CSS, and JavaScript. It works perfectly on PC or big screens, but when viewed on smaller devices like phones or tablets, the display gets cut off and does not adjust properly. Here are some example pictures for ref ...

Discover and transform any strings that begin with http & https into clickable links

Can I use jQuery to search a paragraph for all strings that begin with http & https and turn them into clickable links? I have my Twitter feed displayed on my website, but any lines starting with http & https are shown as regular text. Is it feasible to t ...

The height and rows of a textarea element do not adjust properly to the content in FireFox

Looking for a way to create a textarea with dynamic height that adjusts as the user adds new content? The resize property is set to none and overflow is hidden. It seems to be working correctly in Chrome, but Firefox is presenting some mysterious issues wi ...

Exploring the Form's data-url Attribute

My form tag is set up like this: <form data-id="213" method="post" onsubmit="javascript: startAjax(); return false;"> <input type="submit" value="submit"> </form> When I submit the form, an ajax script runs to validate some information ...

How to minimize the amount of typing needed when specifying grid positions in CSS Grid layout?

(I am currently in the process of upgrading the design of this data entry page from a basic CSS/HTML table layout to something more advanced, utilizing CSS Grid layout). Following common conventions, I have structured it into 12 columns. Each entry field ...

Tips for avoiding anti-aliasing of bitmap font on Internet Explorer and Firefox

I am currently experiencing issues with font smoothing when using a basic bitmap font for icons. While the font appears crisp in Chrome, it appears blurry in IE and FF. Do you have any recommendations on how to resolve this problem? You can view a screen ...

Attempting to migrate a HTML website to WordPress has proven to be a challenge as only the content is visible, with the CSS failing to load properly

I'm looking to convert an HTML site into a WordPress site while keeping the same theme intact. Even after adding 'wp_enqueue_style' to the functions.php file, the CSS file is not being recognized by WordPress. functions.php <?php f ...

Show or hide the sibling element of the current element without using a specific identifier in jQuery

I am looking to make div.edit-button toggle its corresponding sibling div.additionalFieldForm. There are multiple instances of both on the page, so I want to target only the pair that are related within the same group. If a div.edit-button is clicked, the ...

Extracting the number of likes from each post on a specific profile using Python scrapy

Here is the code snippet that I am currently working with: #IMPORT THESE PACKAGES import requests import selenium from selenium import webdriver import pandas as pd #OPTIONAL PACKAGE, BUY MAYBE NEEDED from webdriver_manager.chrome import ChromeDriverManage ...

Choose a specific 24-hour range with the Date Interval Selector

I am currently utilizing the Date Range Picker plugin for bootstrap from the website http://www.daterangepicker.com/#examples, and I have a requirement to set the maximum date time range to be within 24 hours. Below is an example demonstrating how I can s ...

Unable to utilize external JavaScript files in Angular 8

I've been working on integrating an HTML template into my Angular project and for the most part, everything is going smoothly. However, I've encountered an issue where my JS plugins are not loading properly. I have double-checked the file paths i ...

Utilizing jQuery to handle string manipulation via AJAX POST requests

I have been working on developing a checkbox-based filter operation for a website. This feature includes multiple checkboxes that filter a list of records based on different parameters, similar to the implementation found here. So far, I have made progress ...

Ways to eliminate hover effect in CSS

I have a text that is currently displayed as a hyperlink, and some CSS code is causing it to underline and become bold when hovered over. I want to remove the hyperlink, but still keep this style by default without needing to hover over the text. Here is m ...

Is it possible to align an entire column to the right in the Material UI Data Grid?

I'm currently exploring Material UI and grappling with a specific challenge. Is there a method within Material UI to create a Data Grid with two columns, one left-aligned and the other right-aligned? I've managed to align the headers as desired, ...

What is the reason for the ineffectiveness of percentage padding/margin on flex items in Firefox and Edge browsers?

I am trying to create a square div within a flexbox. Here is the code I have used: .outer { display: flex; width: 100%; background: blue; } .inner { width: 50%; background: yellow; padding-bottom: 50%; } <div class="outer"> <div c ...

What could be causing multiple ajax requests to not run concurrently?

I have encountered an issue with my nested AJAX functions - only the first request seems to be executed and I am unsure of the reason behind this behavior. To troubleshoot, I have included some alert messages to track progress. I am working within a Dja ...

Create a dynamic dropbox using JavaScript/JQuery in an HTML page

I am currently working on implementing 3 different drop down boxes that are triggered by 4 different buttons. These drop down boxes should appear within the #apple div. When Button B1 is clicked, the drop down options include Apple, Mango, and Papaya. Whe ...

What are the steps to update content by referencing an id in the hash URL?

Currently, I am utilizing the following code snippet to extract an ID from the hash URL: var integer = window.location.hash.match(/\d+/) | 0; alert(integer); However, I have encountered an issue where upon using the back button after modifying the U ...