How to change the value of feColorMatrix in VueJS

In my Vue Project, I have implemented a component named demo.vue.

This particular component features a complex svg within its <template>. When an element is clicked, the Javascript should alter the color of one of the svg's drop shadows.

The svg design was exported from Figma and after some investigation, I discovered that the desired drop shadow color can be modified as shown below:

<feColorMatrix id="dropshadowID" type="matrix" values="0 0 0 0 1 0 0 0 0 0.233333 0 0 0 0 0.233333 0 0 0 0.25 0" result="hardAlpha"/> 
//The above code snippet represents a red drop shadow

To achieve the color change, the code should resemble this:

<feColorMatrix id=dropshadowID type="matrix" values="0 0 0 0 0.233333 0 0 0 0 1 0 0 0 0 0.31 0 0 0 0.25 0"/>

I attempted to tackle this issue in the following manner:

Javascript:

function changeDropshadow() {
    var target = document.getElementById('dropshadowID')
    target?.classList.add('greenShadow')
}

CSS:

.greenShadow {
    values="0 0 0 0 0.233333 0 0 0 0 1 0 0 0 0 0.31 0 0 0 0.25 0"
}

Unfortunately, CSS does not recognize the values property, leading to the following inquiry:

How can I dynamically change the color of my drop shadow in JavaScript with just a button click?

Answer №1

To update values in Vue code, simply store them in a variable and modify it accordingly.

// template
<feColorMatrix id="dropshadowID" type="matrix" :values="values" result="hardAlpha"/>

<script setup>
const values = ref('0 0 0 0 1 0 0 0 0 0.233333 0 0 0 0 0.233333 0 0 0 0.25 0')
function changeDropshadow() {
    values.value = "0 0 0 0 0.233333 0 0 0 0 1 0 0 0 0 0.31 0 0 0 0.25 0"
}

</script>

Demo

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

Empty value is returned by the Dialog DateTextBox

Using the DateTextBox in a Dialog has resulted in an unexpected issue for me. After selecting a date and submitting the dialog, it returns an empty value. What's even more surprising is that this issue is present in the Dojo demos as well: . Try enter ...

When I receive a 404 response from the API, I aim to start my observable

How can I trigger my observable initialization when receiving a 404 response from the API? The code snippet below is not working as expected. const urlParams = { email: this.email }; this.voicesProfileObservable$ = this.service.request<any>( AVAI ...

Is there a way to display the overall count of items in ReCharts?

I'm curious about how to access the additional data items within the 'payload' field of recharts when using material-ui. Despite my efforts to find relevant sources, I have not come across any references pertaining to accessing other group n ...

Generate a commitment from the function

I know the basics of JavaScript Promise and promise chain, but I'm looking to deepen my understanding. For example, take a look at the method provided below. It's in TypeScript, but can be adjusted for JavaScript ES6. private InsertPersonInDB(p ...

Utilizing ng-options within an ng-repeat to filter out previously chosen options

Facing a simple problem and seeking a solution. I am using ng-repeat to dynamically create select boxes with ng-options displaying the same values. The ng-repeat is used to iterate through model options. <div data-ng-repeat="condition in model.condit ...

Exploring content within a nested directory on AWS S3

I'm currently experimenting with an ajax request in order to retrieve all image files from a specific subfolder within my S3 bucket. Even though I have set the subfolder to public access using the dropdown menu (view image for reference), I keep enco ...

A JavaScript AddEventListener will not execute a function that has parameters

Attempting to execute a function with two parameters in NuxtJS upon clicking an element using AddEventListener. async handleSubmit(recipe, userRating) {some code...} setup(recipe) { document.querySelectorAll('.recipe-rating > .star').forEac ...

Filtering Typeahead results based on multiple fields in Angular

My typeahead feature currently filters based on a person's name only. However, my person object contains additional fields such as surname, and I would like the filter to work based on both name and surname. Here is the existing typeahead code using ...

Slide up a row in the table using jQuery

Currently, I am in the process of creating a unique jQuery plugin that enables users to instantly delete records within a table. One key feature I would like to implement is changing the background-color of the deleted row to red and then smoothly sliding ...

Ways to terminate a NOHUP process for Node.js started through SSH

I have initiated a node.js server on port 3000 using nohup for background running, but now I need to stop the server on the same port and start it again. How can I stop the process? To identify the process in order to kill it, I can use this command: ps ...

Adjust the element to occupy the entire height

To achieve center alignment on the page, I want to expand an element's margin. The first and third elements should stick to the top and bottom, while the second element has a fixed height and needs to be centered. If my explanation isn't clear e ...

Ways to ensure text fits nicely within a container: HTML & CSS

Below is a code snippet: @import url('https://fonts.googleapis.com/css?family=Merriweather|Open+Sans'); .square { max-width: 460px; background: white; border-radius: 4px; box-shadow: 0px 5px 20px #D9DBDF; -webkit-transition: all 0. ...

What's the best way to eliminate blank space in my Bootstrap grid columns?

I'm facing an issue with the search filter layout on my website. It includes input fields for a search term, two datepickers, and two buttons: <div id="search-holder"> <div id="search-box"> <div ...

When using Angular 5's ngModel, the user interface displays the updated value dynamically without requiring the

When filling out my form, I encounter an issue with a select element and a bind variable. If I make a change to the value and save it, everything works as expected. However, if I make a change in a modal window but then close the modal without saving the v ...

"Uncovering the dangers of XMLHttpRequest: How automatic web-page refresh can lead

Hello, I have been developing a web interface for some hardware that utilizes an 8-bit microcontroller. The webpage includes HTML, JavaScript, JSON, and XHR (XMLHttpRequest) for communication purposes. My goal is to create a page that updates every 250 ...

What is the best way to navigate through several URLs using redirection?

A while back, I came across a website that had an interesting feature where it would redirect to multiple pages consecutively. It would redirect to one page for a few seconds, then automatically move onto the next page after a set time interval, and so o ...

Encountering an Unhandled Reference Issue while Using JavaScript and AJAX

This is a td element I created using JavaScript: '<td contenteditable="true" onBlur="saveToDatabase(this,s1,' + d.pid + ')" onClick="showEdit(this);">' + d.s1+ '</td>' + I need to pass the value of the saveToData ...

Troublesome issue with Internet Explorer and Safari: The .click() function does not work for input type="button" in Jquery

Is there a way to ensure that the input type="button" functions properly with jquery function .click() in Internet Explorer and Safari? While it works seamlessly in Mozilla, Chrome, and Opera. For instance, when the button is clicked, a hidden div should b ...

Ways to display HTML code on a webpage

As part of my internship, I am tasked with creating a WYSIWYG editor that can incorporate logic such as if-statements and loops. While there are existing WYSIWYG editors available, none of them seem to support this type of functionality. I am seeking tech ...

What is the best way to retrieve data from nested components?

My project has a nested component structure that looks like this: <component A> <button "save data"> <component B> <form> <component C> <input/> <input/> <input/> ...