1

Is it possible to trigger a javascript function with Browser's zoom-in and zoom-out?

skeletank
  • 2,880
  • 5
  • 43
  • 75
aneeshraj
  • 101
  • 1
  • 9

3 Answers3

2

Yes friends.... Found the solution....

window.onresize = resize;
function resize() {
   alert("Windows is resized...");
}

I hope this will be helpful for you.

OR

This will help you Get Height Width on zoom-in & zoom-out browser

Hardik Patel
  • 67
  • 1
  • 16
1
(window.devicePixelRatio*100).toFixed(0) + '%';

you are not triggered the browser's zoom in/out functions but capture the event. This code helps you to capture the browser's current tab zoom in / zoom out percentage ratio.

run the code : chrome -> console -> create live expression -> paste it & enter.

use chrome zoom in/ out the tab

manoz
  • 91
  • 4
  • 4
    While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – Suraj Rao Nov 06 '20 at 18:27
0

Try it with Jquery & JS :

<script>
function set_body_size() {
  let w = window.innerWidth;
  let h = window.innerHeight;
  $("body").css({ width: w, height: h });
}

set_body_size();
window.addEventListener("resize", resizeThrottler, false);
var resizeTimeout;

function resizeThrottler() {
  // ignore resize events as long as a deferred execution is in the queue
  if (!resizeTimeout) {
    resizeTimeout = setTimeout(function () {
      resizeTimeout = null;
      set_body_size();
    }, 100);
  }
}
</script>