Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
104
rated 0 times [  108] [ 4]  / answers: 1 / hits: 28822  / 6 Years ago, mon, march 12, 2018, 12:00:00

I am using ReactJs. I want to change a position of the image dynamically.



I am trying to set up style like described here:



My sprite.js:



'use strict';
import '../res/my_css.css'

const React = require('react');
const ReactDOM = require('react-dom');

class Sprite extends React.Component {
render() {
var left = 5000 + 'px';
var top = 5000 + 'px';
var padding = 5000 + 'px';
return (
<div id=bird style={{padding:padding, left: left, top:top}}/>
)
}
}

export default Sprite;
ReactDOM.render(
<Sprite />,
document.getElementById('sprite')
)


My css contains:



#bird {
background:url('../res/bird.png');
background-repeat: no-repeat;
}


I see the image, but style={{padding:padding, left: left, top:top}} does not applied.



If I look to the source code in Chrome, I see the style padding:5000px, left:5000px, top:5000px. But my image is in the left top corner.



How can I dinamically change the position of the div element (image in my case) in ReactJs?


More From » html

 Answers
2

Try like this.You have not included position:absolute



class Sprite extends React.Component {
render() {
var left = 5000 + 'px';
var top = 5000 + 'px';
var padding = 5000 + 'px';
return (
<div id=bird style={{padding, left, top,position:'absolute'}}/>
)
}
}

[#54962] Thursday, March 8, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ariel

Total Points: 523
Total Questions: 111
Total Answers: 100

Location: Anguilla
Member since Sun, Jan 29, 2023
1 Year ago
;