current position:Home>React style modification background invalid
React style modification background invalid
2022-04-29 09:19:24【from_ the_ star】
Background introduction
After clicking , Change an opaque button to a progressively transparent button . The code is as follows :
Before clicking :
let style = this.props.style;
style["background"] = "rgba(250,103,37,1)";
//...
return (
<div style={
this.style}> Download now </div>
);
After clicking :
let style = this.props.style;
let progStr= Math.floor(progress*100)+"%";
style["background"] = `linear-gradient(to right,${
this.backColor} ${
progStr}, rgba(39,42,38,0.1) 0%);`;
//...
return (
<div style={
this.style}> Downloaded {
progStr}</div>
);
What happened : modify style After the object , The background color is not refreshed , Or opaque orange .
Problem analysis
1、style Object modification ,react Object reference address comparison is adopted , For it , The style has not been modified , So it won't refresh . Use deep copy to solve .
2、 use 1 after ,style The object is changed , But when displayed , There is also the transparent orange setting before the gradual opacity , Equivalent to
background:rgba(250,103,37,1) linear-gradient(to right,rgba(250,103,37,1) 40%, rgba(39,42,38,0.1) 0%);
In fact, the inline style displayed is
background:linear-gradient(to right,rgba(250,103,37,1) 40%, rgba(39,42,38,0.1) 0%);
Maybe it's my browser kernel , On developer tools , Remove background It can be displayed normally on the tick . For it , I only modify it background-image, No changes background-color, No redrawing .
Using the following method to modify the style can solve :
let style = clone(this.props.style);
style["backgroundColor"] = this.backColor;
style["backgroundImage"] = `linear-gradient(to right,${
this.backColor} ${
progStr}, rgba(39,42,38,0.1) 0%);`;
copyright notice
author[from_ the_ star],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/119/202204290630081056.html
The sidebar is recommended
- Lesson 3 of ROS quick start - subscriber subscriber of ROS
- A lifeless face
- Mock in Vue JS preliminary simple use
- The Java Web servlet triggers the alert box on the front end
- CSS sets the color of the small vertical bar in front of the title
- Incomplete display of CSS background image
- [front end learning notes] save the front-end related codes
- Precautions for AWS serverless design dynamodb
- AWS serverless design - apigateway
- AWS serverless design lambda
guess what you like
AWS serverless design - firewall WAF
AWS serverless design-s3
Python repeated element determination function program
Nginx direction agent solves cross domain Problems-2
The foundation of JavaScript
DOM based on JavaScript
Javascript based BOM
JavaScript advanced functions
Basic summary of JavaScript advanced
Object oriented JavaScript
Random recommended
- JavaScript advanced threading mechanism and event mechanism
- HTML+CSS
- Introduction to less
- CSS3 media query
- Learn about bootstrap
- JQuery learning
- Ajax case
- Ajax sends a post request
- Ajax sends get requests
- Ajax notes
- Ajax learning notes
- Relearn react (1) - recognize the life cycle
- Small problems encountered by react usereducer and Solutions
- CSS realizes the square of adaptive screen width
- Nginx + ModSecurity setup
- Bootstrap web job
- bootstrap
- Swoft 2. X Foundation (HTTP, database, redis)
- Docker actual combat case 2: nginx load balancing
- Vue basic syntax
- Go basic syntax 3 (socket, httpserver)
- Nginx configures HTTPS and calls http
- Nginx parsing vulnerability
- How can the backend package Vue projects quickly
- Netty configures WSS protocol access through nginx (Practical)
- Total permutation problem_ Not containing the same element and containing the same element_ Leetcode46_ Leetcode47_ Backtracking solution + java code
- How to upload and download files using Axios in nodejs
- Vue excel file upload
- CondaHTTPError: HTTP 000 CONNECTION FAILED for url < https://conda.anaconda.org/fastai/noarch/repodat
- Multi function environmental monitoring pole scheme based on wireless gateway
- JPS in Hadoop, but http://hadoop01:50070/ How to solve the problem if there is no interface? 500ha70 cluster can't be accessed?
- Tool class for obtaining specific information in HTTP request
- UAV project tracking record 65 - wireless transceiver module circuit
- UAV project tracking record 76 - wireless transceiver module circuit
- Basic concept of angular velocity
- Front end login password encryption and decryption
- Vue parent-child component mutual transmission and intermodulation
- Vue nested loop array, select one of them and add the selected style
- The Vue seamless scroll list scrolls automatically
- Vue line graph moves dynamically to the right