PageSourceSearch

https://tianweiy.github.io/dmd2/static/js/magnifier.js

js tianweiy.github.io collected 2026-10-03 10:05:00 UTC 2,292 bytes, 58 lines download raw bytes

1function magnify(imgID, zoom) {
2  var img, glass, w, h, bw;
3  img = document.getElementById(imgID);
4  /*create magnifier glass:*/
5  glass = document.createElement("DIV");
6  if (zoom <= 0){
7	glass.setAttribute("class", "img-magnifier-glass_init");
8    }else {
9        glass.setAttribute("class", "img-magnifier-glass");
10    }
11  /*insert magnifier glass:*/
12  img.parentElement.insertBefore(glass, img);
13  /*set background properties for the magnifier glass:*/
14  glass.style.backgroundImage = "url('" + img.src + "')";
15  glass.style.backgroundRepeat = "no-repeat";
16  glass.style.backgroundSize = (img.width * zoom) + "px " + (img.height * zoom) + "px";
17  bw = 3;
18  w = glass.offsetWidth / 2;
19  h = glass.offsetHeight / 2;
20  /*execute a function when someone moves the magnifier glass over the image:*/
21  glass.addEventListener("mousemove", moveMagnifier);
22  img.addEventListener("mousemove", moveMagnifier);
23  /*and also for touch screens:*/
24  glass.addEventListener("touchmove", moveMagnifier);
25  img.addEventListener("touchmove", moveMagnifier);
26  function moveMagnifier(e) {
27    var pos, x, y;
28    /*prevent any other actions that may occur when moving over the image*/
29    e.preventDefault();
30    /*get the cursor's x and y positions:*/
31    pos = getCursorPos(e);
32    x = pos.x;
33    y = pos.y;
34    /*prevent the magnifier glass from being positioned outside the image:*/
35    if (x > img.width - (w / zoom)) {x = img.width - (w / zoom);}
36    if (x < w / zoom) {x = w / zoom;}
37    if (y > img.height - (h / zoom)) {y = img.height - (h / zoom);}
38    if (y < h / zoom) {y = h / zoom;}
39    /*set the position of the magnifier glass:*/
40    glass.style.left = (x - w) + "px";
41    glass.style.top = (y - h) + "px";
42    /*display what the magnifier glass "sees":*/
43    glass.style.backgroundPosition = "-" + ((x * zoom) - w + bw) + "px -" + ((y * zoom) - h + bw) + "px";
44  }
45  function getCursorPos(e) {
46    var a, x = 0, y = 0;
47    e = e || window.event;
48    /*get the x and y positions of the image:*/
49    a = img.getBoundingClientRect();
50    /*calculate the cursor's x and y coordinates, relative to the image:*/
51    x = e.pageX - a.left;
52    y = e.pageY - a.top;
53    /*consider any page scrolling:*/
54    x = x - window.pageXOffset;
55    y = y - window.pageYOffset;
56    return {x : x, y : y};
57  }
58}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.