Leverage JQuery's Range Slider for Real-Time CSS Value Updates

Trying to dynamically update CSS properties such as minmax(20vw), grid-gap, and height using individual range sliders:

#wrapper {
grid-template-columns: repeat(auto-fit, minmax(20vw, 1fr));
grid-gap: 20px;
}

#item {
height: 150px;
}

Utilizing CSS grid and 'VW values', not sure if it's complicating the process. Any guidance on where to start is appreciated.

Editable live codepen available here: https://codepen.io/db13/pen/ypdPOO

UPDATE: Each range slider will now correspond to a specific property:
Slider 1: Grid Gap
Slider 2: Div width
Slider 3: Div Height

Answer №1

To achieve the desired result, utilize a different CSS property as shown in the example below:

// Updating gap
$("#slider-grid").on('input change', function(e) {
    var minmax = this.value;
    $("#wrapper").css("grid-gap", minmax + 'px')
});

// Adjusting height
$("#slider-height").on('input change', function(e) {
    var minmax = this.value;
    $(".item").css("height", minmax + 'px')
});

// Modifying width
$("#slider-width").on('input change', function(e) {
    var minmax = this.value;
    $("#wrapper").css("grid-template-columns", "repeat(auto-fit, minmax(" + minmax + "vw, 1fr))")
});

Check out the CodePen Link - V2

Implement these changes and hopefully it will be helpful for you.

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

What is the best way to add an active class to a clicked menu item that already has a class

I have menu items on the master page, and if users click on that menu item, I want to show it as active. My goal is to append "Active" to the existing class to indicate that it is active. _Layout.cshtml: <div class="menu-items-navigation"> <di ...

The event listener attached to this model is failing to trigger when there are

The issue is that the "change" event is not being triggered in the code snippet below. var PageView = Backbone.View.extend({ el: $("body"), initialize: function(){ this.model.on("change:loading", this.loader, this); }, loader: func ...

Guide on redirecting to the login page in angular2 when a process is left incomplete

I am facing an issue with the Popup used for device verification during login. When I click on the login button with valid credentials, a popup opens if the device is not trusted. Once I provide the necessary information and successfully validate, it shoul ...

Reasons why text does not show color when a style element is applied

I attempted to include a color and font family within an H1 tag using style, but unfortunately it did not work as expected. The color property had no effect on my current line of text. <h1 align="center" style="font-family: Arial, Helvetica, sans-serif ...

How can I retrieve the value of a JavaScript variable using Ajax?

Hello everyone! I've been a long-time user of various programming forums, but this is my first time posting. Lately, I created a really simple browser-based game, and when I say simple, I mean it's incredibly basic. The whole game logic resides ...

Preserving the initial input values in a secure manner for future reference, utilizing either an object or a

Recently, I've started revisiting a script I created a while back that checks for changes in a form to prompt a message asking 'Would you like to save your changes?'... One thing that's been on my mind is whether I should store the ori ...

How come I am unable to expand a collection of objects using Zustand?

I am currently utilizing Zustand in a TypeScript Next.js application. Strangely, whenever I attempt to loop through my state object, I encounter a runtime error message. The structure of the damaged zone object for my car is as follows: const damagedZones ...

What are some alternative methods for organizing folder structure in Express Handlebars when managing views?

Is there a more efficient way to render HTML files without constantly needing them to have different names? I'm looking for a method where handlebars can identify which file in which folder to render, without encountering conflicts with files of the s ...

Selenium Python option other than using send_keys()

I was looking to enhance the efficiency of this Python code and found a faster alternative: driver.get(myUrl) message = driver.find_element_by_id('message') send = driver.find_element_by_id('submit') for _ in range(myRange): messa ...

What is the best way to ensure consistent Box Overlay Height across multiple boxes?

Is there a way to ensure that overlay box height remains the same even if the text lines are not the same length? Below is a snippet of my code. If you have a solution using jQuery or JS, please provide it. Thank you for your time and effort in trying to h ...

Ways to execute a task based on various selection option values?

Is there a way to dynamically change the API key value based on the selected currency option? For example, I want to display prices in different currencies like INR, USD, EUR, etc., each requiring a different API key. <select class="form-select for ...

Can you customize the buttons in the operation panel of an antd image preview window?

https://i.sstatic.net/hZLOn.png I am looking to add a button that allows users to download or share the image being previewed. Is there a way to achieve this functionality? I have researched and read through the documentation but have not found a solutio ...

How can certain HTML be redirected or hidden for users on mobile devices?

Lately, I've been putting the final touches on my website to present to potential employers as I will soon be starting my job search after graduation. I recently added an "about" section with parallax scrolling effect, but unfortunately, it's not ...

Creating an Engaging Data Visualization: Blending Candlestick Insights with Line Graphs

I'm attempting to display a moving average on a candlestick chart, but I'm facing an issue where the path of the line is not fully appearing on the SVG canvas that I've created. I've searched through various posts to understand how to o ...

Avoiding metacharacters and utilizing them as a string variable for selection

For example, I have a variable called myid, and its value is "abc xyz". Then, I use a function to escape metacharacters and assign the result to another variable like this: var x = "#"+escapechars(myid);. The evaluated value of x is #abc\\xyz. ...

Accessing Private Files with Signed URLs from AWS S3

Issue: The challenge is to securely allow users to upload a file and retrieve it later. The files are stored in private Buckets and objects using S3 pre-signed URLs for uploading. However, fetching the file poses a problem as the signed URLs expire after ...

Choose several identifiers that possess strikingly similar titles

I am dealing with a form that is dynamically generated by a third-party provider and unfortunately I am unable to modify it... However, I am looking for a solution to select all IDs that begin with the same string, such as: easi_fielddiv_LastName, easi_fi ...

Ways to decrease the width of a outlined material icon

Is there a way to adjust the appearance of this icon to make it appear thinner? I have tried using font-weight and stroke-width without success. .material-icons-outlined, .material-icons.material-icons--outlined { font-family: 'Material Icons Out ...

Transition the object in smoothly after the slide has changed

How can I make the h4 tags fade in after the divs slide into view, while also adding the class "current" to each visible slide? Check out the example on JSFiddle here. <div class="slider"> <div class="slides"> <div class="slide ...

How to position one div next to another using CSS and HTML

Hey there, I'm facing an issue with creating a sidenav next to a div containing paragraphs and images. I can't seem to make both the sidenav and the other div appear inline. If anyone has any insights on how to solve this problem or spot what I&a ...