Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
Django, how to add zoom in/zoom out functionality into preview function in javascript?(js)

i have a js function that previews the image on button click before uploading. I want to add the functionality of zoom in and zoom out to that preview. How can I do that? Following is the code I am using:

<tr>
              <th><label style="display: inline;" for="id_image">Image:</label></th>
              <td>
                
                <input type="file" name="image" accept="image/*" id="id_image"  onchange="showPreview(event)" {{form.image}}
                    
              </td>
            </tr>

And function to preview before uploading:

<script>
        

        function showPreview(event){

            if(event.target.files.length > 0){
                var src = URL.createObjectURL(event.target.files[0]);
                var preview = document.getElementById("file-ip-1-preview");
                preview.src = src;
                preview.style.display = "block";
                                            }                              
                                         }                                    
    </script>  

Ad here is the working zoom function that I want to incorporate in the preview function.


    {% comment %} ZOOM IMAGE with + and - Buttons {% endcomment %}
<script>

  function zoomin(){
    
    var myImg = document.getElementById("map");
    var currWidth = myImg.clientWidth;
    if(currWidth == 2500) return false;
     else{
        myImg.style.width = (currWidth + 100) + "px";
    } 
}
  function zoomout(){
    
    var myImg = document.getElementById("map");
    var currWidth = myImg.clientWidth;
    if(currWidth == 100) return false;
      else{
        myImg.style.width = (currWidth - 100) + "px";
    }
}

</script>

<div id="navbar">
  <button type="button" onclick="zoomin()"> <h6>+</h6> </button>
  <button type="button" onclick="zoomout()"> <h6>--</h6> </button>
  </div>
  
  <div class="main">
  <img id="map" src="IMAGE SOURCE HERE" />

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!