Enhance images using css or javascript

I have a quick query regarding website image editing.

I was tasked with incorporating a rating system where users can give 1-2 or 3 star ratings. Each item will display only one star. The requirement is that the star updates as shown in the examples below:

https://i.sstatic.net/MbgNX.png = 100%

https://i.sstatic.net/QNfZu.png = 70%

Now here's my question: is there a way to achieve this using CSS or JavaScript without having to use multiple images?

Thank you for your help

Answer №1

There's definitely a way to make this happen.

  1. Start by showing the star image on the screen.
  2. Next, overlay a radial progress bar on top of the star with reverse progress. One side will be white while the other side is transparent.

    For detailed instructions on creating a radial progress bar, you can check out this link.

CSS Styles

@import url(https://fonts.googleapis.com/css?family=Lato:700);

.size(@width, @height) {
  height: @height;
  width: @width;
}

// Styling for different elements
*,
*:before,
*:after {
  box-sizing: border-box;
}

html,
body {
  background: #ecf0f1;
  color: #444;
  font-family: 'Lato', Tahoma, Geneva, sans-serif;
  font-size: 16px;
  padding: 10px;
}

.set-size {
  font-size: 10em;
}

.charts-container:after {
  clear: both;
  content: "";
  display: table;
}

// More CSS styling...

HTML Markup

<div class="set-size charts-container">
    <div class="pie-wrapper progress-30">
        <span class="label">30<span class="smaller">%</span></span>
        <div class="pie">
            <div class="left-side half-circle"></div>
            <div class="right-side half-circle"></div>
        </div>
    </div>

    <!-- Add more pie-wrapper divs with different progress percentages here -->
</div>

Answer №2

Utilize image sprite, which means that in theory, you're only loading a single image.

Answer №3

To create a unique effect, I would place a pie-segment over the image and adjust its size accordingly. It's important to ensure that the color of the segment matches the background of the page for a seamless look.

For implementation, refer to: https://codepen.io/sandeepshah/pen/eEqLpv

<div class="pie"></div>

.pie {
  position: absolute;
  width: 100px;
  height: 200px;
  overflow: hidden;
  left: 0;
  top: 0;
  transform-origin: left center;
}

.pie:BEFORE {
  content: "";
  position: absolute;
  height: 200px;
  width: 100px;
  left: -100px;
  border-radius: 100px 0 0 100px;
  transform-origin: right center;
  background-color: red;
  transform: rotate(60deg);
}

The "transform" attribute can be used to adjust the size of the pie-segment effectively.

Answer №4

If you're looking to create a custom star shape using HTML5 canvas, consider referencing resources like this and this. One approach is to use a background image of a full star within a square canvas element, adjusting its dimensions dynamically with jQuery. Alternatively, you could utilize a div container with six images representing different parts of the star, each rotated to various angles. To display only specific segments of the star, such as hiding 50% with three images hidden, manipulate their visibility accordingly.

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

Mastering the Effect of .fadeIn() in Combination with .after() Method

Could you help me understand why the .fadeIn() function is not working properly in this code? My goal is to combine the .after() and .fadeIn() functions together. $("input").blur(function(){ $(this).after('<div class="err">There is an Error&l ...

Is there a way to restrict a forEach loop so that it only runs 16 iterations?

I'm looking to limit the number of results shown in a forEach loop to only 16. Is there a way to achieve this? <div class="events-list" data-bind="if: (typeof(Events) != 'undefined')" style="padding-top:5px; padding-bottom:5px;"> ...

Transforming a curl command into an AJAX request

Can someone help me with using an API by inputting a curl command through AJAX? Any guidance is greatly appreciated. Here is the curl command I am struggling with: curl -H “Authorization: Token #{auth_token}” -X GET http://localhost:3000/api/v1/basket ...

Could the problem with inset box-shadow and large border-radius on one side be related to Chrome?

Have you noticed a discrepancy in the inset box-shadow behavior with large border-radius on one side, particularly in Chrome? I'm curious about which browser is showing accurate results. Here's how it appears in Chrome: https://i.stack.imgur. ...

Loading bar MVC3

I've integrated an upload function into my application. This feature allows users to upload an Excel file, which is then parsed and the data is copied to the database. While the actual upload process doesn't take too long, the parsing can be time ...

Exploring Bing Maps with JavaScript: Implementing Infobox opening functionality upon clicking PushPin

I've been experimenting with the sample code provided on the Bing SDK site, and I'm facing an issue with getting the click event to work with pushpins that are added in a JavaScript .each loop. The loop pulls in longitude and latitude coordinates ...

Excessive greed in 2 column layout is causing left alignment issues

Check out the sample code here: http://jsfiddle.net/YUhgb/ HTML Markup <html> <body> <div class="left"></div> <div class="right"> <div class="container"> <div class="i ...

Animating or transitioning CSS keyframes to an inline value when the page is initially loaded

In my current project, I am working on creating HTML and CSS-based bar representations of percentage values. The structure of the code is as follows: Using HTML: <div class="chart"> <div class="bar" style="width:43%"></div> </div&g ...

The issue with the search box not being correctly displayed on Google CSE using Twitter Bootstrap

Having an issue with the Google Custom Search (CSE) as it is not displaying the search box and button correctly. I am using Twitter Bootstrap v3.1.0. <script> (function() { var cx = '009077552906670546181:2ufng0dmsos'; ...

Ways to personalize the arrow component in react-popper

How can I match the arrow style with the popper appearance? import React from "react"; import ReactDOM from "react-dom"; import { Manager, Reference, Popper } from "react-popper"; function App() { return ( <Manager> <Reference> ...

Angular dependency injection function

What is the best placement for the common handleError and handleSuccess functions? These functions are commonly used by every service. Where should these functions be placed? Should they be global functions injected as dependencies? (function () { "u ...

Encountering the "ERPROTO" error message while attempting to send an Axios request from my REST API

I have set up my API at "localhost:3000/api/shopitems" and it successfully returns the JSON data below when accessed through a browser: [ { "item_available_sizes": { "s": 1 }, "imgs": { "album": [], ...

When the main index.html page is accessed, a specific HTML sub-page is dynamically loaded into a div

Is there a way to load a specific sub-page into a div tag when the website is loading? Here's an example of the div: <div id="content-main"> </div> I need to make sure that only a certain sub HTML document is loaded once the main index ...

What is the technique for enabling a mouse click in the vicinity of an element?

During a presentation on React at a conference, I witnessed the speaker introduce a feature that allowed users to click and drag a divider on the screen by simply getting close to it instead of having to click directly on it. This concept adds to usabilit ...

Creating a stylish background gradient between two handles on a jQuery Slider with CSS

After watching a presentation by Lea Verou on CSS Variables titled CSS Variables: var(--subtitle);, I was inspired to create a gradient effect between jQuery Slider handles: $(function() { var max = 400; var $slider = $('.slider'); funct ...

Setting the size of a box using CSS in HTML pages

I am facing issues with resizing boxes. Below is the code snippet: <!DOCTYPE html> <html lang="en"> <head> <style> .wrapper { text-align: center; } #bubble { display: inline; -moz ...

Alert will only occur once the done function in jquery's .ajax method is executed

Something seems off and I'm struggling to understand the situation. I've used jQuery's .ajax() function to run a script that retrieves data from the database. The script is functioning properly and the data is being returned as expected: $. ...

Dividing a string starting from the first appearance of a specific character

I need assistance with parsing multiple lines of text found in log files following this specific format: topic, the message part, contains occasional commas. Is there a method to separate the string starting from the first comma so that I can store the t ...

Place the logo in the top right corner of the div

Why isn't my logo showing up in the top right corner of my div? .service-title { width: 100%; font-size: 24px; line-height: 1.1em; padding: 1em; background-position: right top; background: orange; background-image: url('http://ve ...

The Bootstrap validator triggers the form submission only after the second click

When I click on the submit button, I am attempting to submit a form that has its default action prevented and first checks a condition before proceeding. Below is the code snippet: $('#payment-form').bootstrapValidator({ live: 'dis ...