N
N
nathan1117772019-06-16 15:07:12
React
nathan111777, 2019-06-16 15:07:12

How to rewrite existing code using React?

There is a code where the image, when you click on it, becomes larger, almost full screen (modal image).
How would such JS code look like in React?

<!--HTML:-->
<div class="portfolio">
<div class="portfolio-container">
<div class="foto-container">
 <img class="foto-portfolio" src="https://libreshot.com/wp-content/uploads/2017/09/Desert-Lizards.jpg" style="width:100%;max-width:300px">
</div>
</div>
<div id="myModal" class="modal-portfolio">
  <span class="close">&times;</span>
  <img class="modal-content" id="img01">
</div>
</div>



<!--CSS:-->
<style>
.foto-portfolio{
  border-radius: 5px;
  cursor: pointer;
  transition: 0.3s;
}
.foto-portfolio:hover {
    opacity: 0.7;
    }

.modal-portfolio {
  display: none; 
  position: fixed; 
  z-index: 100; 
  padding-top: 100px; 
  left: 0;
  top: 0;
  width: 100%; 
  height: 100%; 
  overflow: auto; 
  background-color: rgb(0,0,0); 
  background-color: rgba(0,0,0,0.7);
}

.modal-content {
  margin: auto;
  display: block;
  width: 80%;
  max-width: 700px;
}

.close {
  position: absolute;
  top: 15px;
  right: 35px;
  color: #f1f1f1;
  font-size: 100px;
  font-weight: bold;
  transition: 0.3s;
}
</style>



<!--JS:-->
<script>
var modal = document.getElementById('myModal');
var modalImg = document.getElementById("img01");
var modal = document.getElementById('myModal');
var img = document.getElementsByClassName("foto-portfolio");

for( var i = 0; i < img.length; i++){
  img[i].addEventListener('click', function(){
    modal.style.display = "block";
    modalImg.src = this.src;
  });
}

var span = document.getElementsByClassName("close")[0];
span.onclick = function() { 
  modal.style.display = "none";
}
</script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-06-16
@nathan111777

https://jsfiddle.net/g53Led6h/
or
https://jsfiddle.net/g53Led6h/1/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question