Bildschirmlupe.html


Quell Code


<!DOCTYPE HTML>
    <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"></script>
<style>
  body{
    display: flex;
    flex-direction:column;
    flex-wrap: wrap;
    align-content: center;
    align-items: center;
  }
  h1,p{
    text-align:center;
  }
  #myimage{
    width:600px;
    height:auto;
  }
  #butt{
    width:100px;
    margin-left:calc(50% - 50px);
  }


.img-magnifier-glass {
  position:relative;
  z-index:1;
width: 100px;
height: 100px;
  border-radius:50%;
  border:2px solid blue;

}

  .lupe{
    width:200px;
    height:200px;
  }
</style>

<script>
function magnify(imgID, zoom) {
var img, glass, w, h, bw;
img = document.getElementById(imgID);
glass = document.createElement("DIV");
glass.setAttribute("class", "img-magnifier-glass");
img.parentElement.insertBefore(glass, img);
glass.style.backgroundImage = "url('" + img.src + "')";
glass.style.backgroundRepeat = "no-repeat";
glass.style.backgroundSize = (img.width * zoom) + "px " + (img.height * zoom) + "px";
bw = 3;
w = glass.offsetWidth / 2;
h = glass.offsetHeight / 2;
glass.addEventListener("mousemove", moveMagnifier);
img.addEventListener("mousemove", moveMagnifier);
glass.addEventListener("touchmove", moveMagnifier);
img.addEventListener("touchmove", moveMagnifier);
function moveMagnifier(e) {
var pos, x, y;
e.preventDefault();
pos = getCursorPos(e);
x = pos.x;
y = pos.y;
if (x > img.width - (w / zoom)) {x = img.width - (w / zoom);}
if (x < w / zoom) {x = w / zoom;}
if (y > img.height - (h / zoom)) {y = img.height - (h / zoom);}
if (y < h / zoom) {y = h / zoom;}
glass.style.left = (x - w) -220+ "px";
glass.style.top = (y - h) +120+ "px";
glass.style.backgroundPosition = "-" + ((x * zoom) - w + bw) + "px -" + ((y * zoom) - h + bw) + "px";
}

function getCursorPos(e) {
var a, x = 0, y = 0;
e = e || window.event;
a = img.getBoundingClientRect();
x = e.pageX - a.left;
y = e.pageY - a.top;
x = x - window.pageXOffset;
y = y - window.pageYOffset;
return {x : x, y : y};

}

}

function Testfunktion() {
document.getElementById("myimage").style.visibility = "visible";
magnify("myimage", 3);

}
</script>
</head>
<body>
<div align = "center">
<h1>Image Magnifier Glass</h1>
<p>Mouse over the image:</p>
<input type = "button" value = "KLICK" onclick = "Testfunktion();"/><br><br>
<div class="img-magnifier-container">
<img id="myimage" src="https://www.w3schools.com/howto/img_nature.jpg" width="600" height="400" style = "visibility:hidden"/>
</div>
</div>
</body>
</html>
  1. <!DOCTYPE HTML>
  2. <meta charset="utf-8">
  3. <meta name="viewport" content="width=device-width, initial-scale=1">
  4. <head>
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"></script>
  7. <style>
  8. body{
  9. display: flex;
  10. flex-direction:column;
  11. flex-wrap: wrap;
  12. align-content: center;
  13. align-items: center;
  14. }
  15. h1,p{
  16. text-align:center;
  17. }
  18. #myimage{
  19. width:600px;
  20. height:auto;
  21. }
  22. #butt{
  23. width:100px;
  24. margin-left:calc(50% - 50px);
  25. }
  26. .img-magnifier-glass {
  27. position:relative;
  28. z-index:1;
  29. width: 100px;
  30. height: 100px;
  31. border-radius:50%;
  32. border:2px solid blue;
  33. }
  34. .lupe{
  35. width:200px;
  36. height:200px;
  37. }
  38. </style>
  39. <script>
  40. function magnify(imgID, zoom) {
  41. var img, glass, w, h, bw;
  42. img = document.getElementById(imgID);
  43. glass = document.createElement("DIV");
  44. glass.setAttribute("class", "img-magnifier-glass");
  45. img.parentElement.insertBefore(glass, img);
  46. glass.style.backgroundImage = "url('" + img.src + "')";
  47. glass.style.backgroundRepeat = "no-repeat";
  48. glass.style.backgroundSize = (img.width * zoom) + "px " + (img.height * zoom) + "px";
  49. bw = 3;
  50. w = glass.offsetWidth / 2;
  51. h = glass.offsetHeight / 2;
  52. glass.addEventListener("mousemove", moveMagnifier);
  53. img.addEventListener("mousemove", moveMagnifier);
  54. glass.addEventListener("touchmove", moveMagnifier);
  55. img.addEventListener("touchmove", moveMagnifier);
  56. function moveMagnifier(e) {
  57. var pos, x, y;
  58. e.preventDefault();
  59. pos = getCursorPos(e);
  60. x = pos.x;
  61. y = pos.y;
  62. if (x > img.width - (w / zoom)) {x = img.width - (w / zoom);}
  63. if (x < w / zoom) {x = w / zoom;}
  64. if (y > img.height - (h / zoom)) {y = img.height - (h / zoom);}
  65. if (y < h / zoom) {y = h / zoom;}
  66. glass.style.left = (x - w) -220+ "px";
  67. glass.style.top = (y - h) +120+ "px";
  68. glass.style.backgroundPosition = "-" + ((x * zoom) - w + bw) + "px -" + ((y * zoom) - h + bw) + "px";
  69. }
  70. function getCursorPos(e) {
  71. var a, x = 0, y = 0;
  72. e = e || window.event;
  73. a = img.getBoundingClientRect();
  74. x = e.pageX - a.left;
  75. y = e.pageY - a.top;
  76. x = x - window.pageXOffset;
  77. y = y - window.pageYOffset;
  78. return {x : x, y : y};
  79. }
  80. }
  81. function Testfunktion() {
  82. document.getElementById("myimage").style.visibility = "visible";
  83. magnify("myimage", 3);
  84. }
  85. </script>
  86. </head>
  87. <body>
  88. <div align = "center">
  89. <h1>Image Magnifier Glass</h1>
  90. <p>Mouse over the image:</p>
  91. <input type = "button" value = "KLICK" onclick = "Testfunktion();"/><br><br>
  92. <div class="img-magnifier-container">
  93. <img id="myimage" src="https://www.w3schools.com/howto/img_nature.jpg" width="600" height="400" style = "visibility:hidden"/>
  94. </div>
  95. </div>
  96. </body>
  97. </html>
<!DOCTYPE HTML>
    <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"></script>
<style>
  body{
    display: flex;
    flex-direction:column;
    flex-wrap: wrap;
    align-content: center;
    align-items: center;
  }
  h1,p{
    text-align:center;
  }
  #myimage{
    width:600px;
    height:auto;
  }
  #butt{
    width:100px;
    margin-left:calc(50% - 50px);
  }


.img-magnifier-glass {
  position:relative;
  z-index:1;
width: 100px;
height: 100px;
  border-radius:50%;
  border:2px solid blue;

}

  .lupe{
    width:200px;
    height:200px;
  }
</style>

<script>
function magnify(imgID, zoom) {
var img, glass, w, h, bw;
img = document.getElementById(imgID);
glass = document.createElement("DIV");
glass.setAttribute("class", "img-magnifier-glass");
img.parentElement.insertBefore(glass, img);
glass.style.backgroundImage = "url('" + img.src + "')";
glass.style.backgroundRepeat = "no-repeat";
glass.style.backgroundSize = (img.width * zoom) + "px " + (img.height * zoom) + "px";
bw = 3;
w = glass.offsetWidth / 2;
h = glass.offsetHeight / 2;
glass.addEventListener("mousemove", moveMagnifier);
img.addEventListener("mousemove", moveMagnifier);
glass.addEventListener("touchmove", moveMagnifier);
img.addEventListener("touchmove", moveMagnifier);
function moveMagnifier(e) {
var pos, x, y;
e.preventDefault();
pos = getCursorPos(e);
x = pos.x;
y = pos.y;
if (x > img.width - (w / zoom)) {x = img.width - (w / zoom);}
if (x < w / zoom) {x = w / zoom;}
if (y > img.height - (h / zoom)) {y = img.height - (h / zoom);}
if (y < h / zoom) {y = h / zoom;}
glass.style.left = (x - w) -220+ "px";
glass.style.top = (y - h) +120+ "px";
glass.style.backgroundPosition = "-" + ((x * zoom) - w + bw) + "px -" + ((y * zoom) - h + bw) + "px";
}

function getCursorPos(e) {
var a, x = 0, y = 0;
e = e || window.event;
a = img.getBoundingClientRect();
x = e.pageX - a.left;
y = e.pageY - a.top;
x = x - window.pageXOffset;
y = y - window.pageYOffset;
return {x : x, y : y};

}

}

function Testfunktion() {
document.getElementById("myimage").style.visibility = "visible";
magnify("myimage", 3);

}
</script>
</head>
<body>
<div align = "center">
<h1>Image Magnifier Glass</h1>
<p>Mouse over the image:</p>
<input type = "button" value = "KLICK" onclick = "Testfunktion();"/><br><br>
<div class="img-magnifier-container">
<img id="myimage" src="https://www.w3schools.com/howto/img_nature.jpg" width="600" height="400" style = "visibility:hidden"/>
</div>
</div>
</body>
</html>

vConsole
09:57:22
Uncaught TypeError: Cannot read properties of null (reading 'style')
/Kurze-Scripte-und-Codeschnipsel/index.php?name=Bildschirmlupe.html&ordner=Kurze-Scripte-und-Codeschnipsel:2751:53
09:57:24
772
09:57:22
WeChatLib: 0 (xxxx.xx.xx)
09:57:24
System: Unknown
09:57:24
Protocol: HTTPS
09:57:24
UA: Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
09:57:24
navigationStart: 1744106242017
09:57:24
navigation: 9ms
09:57:24
dns: 132ms
09:57:24
tcp (ssl): 238ms (128ms)
09:57:24
request: 220ms
09:57:24
response: 59ms
09:57:24
domComplete (domLoaded): 1593ms (1490ms)
09:57:24
loadEvent: 15ms
09:57:24
total (DOM): 2212ms (2197ms)