Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9076501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:07:17+00:00 2026-06-16T19:07:17+00:00

I have this resizing script I got from an answer I found on SO.

  • 0

I have this resizing script I got from an answer I found on SO.

<script type="text/javascript">
  function resizeImg(img)
  {
    var resize = 150;
    var origH  = 61;
    var origW  = 250;
    var mouseX = event.x;
    var mouseY = event.y;
    var newH   = origH * (resize / 100);
    var newW   = origW * (resize / 100);

    img.style.height = newH;
    img.style.width  = newW;

    var c = img.parentNode;

    c.scrollLeft = (mouseX * (resize / 100)) - (newW / 2) / 2;
    c.scrollTop  = (mouseY * (resize / 100)) - (newH / 2) / 2;
  }
</script>

It is located in the HEAD placeholder tag in my page.

In the same page, in the content placeholder, I have an <img> tag which needs to run the function above ‘onclick’.

Therefore, It needs to return ‘this’ like this:

<img src="someImage.jpg" alt="" onclick="resizeImg(this)" />

However, this doesn’t work. I have no idea how to do this and I tried searching google for some time now but nothing came up.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T19:07:18+00:00Added an answer on June 16, 2026 at 7:07 pm

    Not sure from where you have copied the source. I suspect event.x, event.y – shouldn’t you be using clientx and clienty properties. Besides, for cross-browser, you need to manage the event reference and image element can be obtained from event object’s target.

    Anyway, try out modified code as below:

    <script type="text/javascript">
    
        function resizeImg(e)   {     
            var event = window.event || e;
            var img = event.target || event.srcElement;
            var resize = 150;     
            var origH  = 61;     
            var origW  = 250;     
            var mouseX = event.clientX;     
            var mouseY = event.clientY;     
            var newH   = origH * (resize / 100);     
            var newW   = origW * (resize / 100);      
            img.style.height = newH + 'px';     
            img.style.width  = newW + 'px';      
            var c = img.parentNode;      
            c.scrollLeft = (mouseX * (resize / 100)) - (newW / 2) / 2;     
            c.scrollTop  = (mouseY * (resize / 100)) - (newH / 2) / 2;   
    }
    
    </script>
    <div>
    <img src="someImage.jpg" alt="" onclick="resizeImg(event)" />
    </div>
    

    I have created the jsfiddle for the same.

    Lastly, consider using productivity library such as jquery which will make things a lot simpler.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this from tinymce and i called it before calling jquery.. <script type=text/javascript
I'm a javascript novice, I have this bit of code in a jsx script
Ok I have seen many posts on this script. Which can be found..... http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/
I have a script that does images resizing on load: $( document ).ready( function()
I have a HttpHandler for resizing images, round corners, reflection etc etc. This i
I have this function // add history paths and save data function AddPath( strTag,
i have this script below that will resize the .content on window resize it
I currently have this folder structure: img.domain.com/ boats/ boat1/ 1.jpg 2.jpg trees/ tree1/ 1.jpg
I have a PHP function that I use regularly for working with images (resizing,
..got a tiny little problem with mouse position after resizing browser window. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.