Масштаб изображения не отображается - PullRequest
1 голос
/ 01 мая 2020

извините за мой Engli sh ..

Я попробую этот javascript код w3schools .

Разница между моими и ними заключается в том, что Я хочу, чтобы мой результат отображался в том же окне.

Как выглядит код;

Верх сверху;

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css" rel="stylesheet"/>
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/js/bootstrap.min.js">  </script>
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">

В стиле,

* {box-sizing: border-box;}

.grosse-bild {
  position: relative;
}
.img-zoom-lens {
 position: absolute;
 border: 1px solid #d4d4d4;
 /*set the size of the lens:*/
 width: 40px;
 height: 40px;
}
.grosse-bild .kleine-fenster {
  border: 1px solid #d4d4d4;
 /*set the size of the result div:*/
 width: 300px;
 height: 300px;
}
.grosse-bild {  padding: 40px;  background-color: #dedee0;  width: 53.7%;    }

.kleine-fenster{
 width: 50%;

 border: none;
 padding-top: 5px;
 display: block;
 margin-left: auto;
 margin-right: auto;

}

Код Javascript,

<script>
      // Initiate zoom effect:
    imageZoom("myresult", "myimage");
</script>

и

function imageZoom(resultID, imgID) {
  var img, lens, result, cx, cy;
  img = document.getElementById(imgID);
  result = document.getElementById(resultID);
    /*create lens:*/
  lens = document.createElement("DIV");
  lens.setAttribute("class", "img-zoom-lens");
     /*insert lens:*/
  img.parentElement.insertBefore(lens, img);
  /*calculate the ratio between result DIV and lens:*/
  cx = result.offsetWidth / lens.offsetWidth;
  cy = result.offsetHeight / lens.offsetHeight;
 /*set background properties for the result DIV:*/
 result.style.backgroundImage = "url('" + img.src + "')";
 result.style.backgroundSize = (img.width * cx) + "px " + (img.height * cy) + "px";
 /*execute a function when someone moves the cursor over the image, or the lens:*/
 lens.addEventListener("mousemove", moveLens);
 img.addEventListener("mousemove", moveLens);
 /*and also for touch screens:*/
 lens.addEventListener("touchmove", moveLens);
 img.addEventListener("touchmove", moveLens);
function moveLens(e) {
  var pos, x, y;
 /*prevent any other actions that may occur when moving over the image:*/
  e.preventDefault();
  /*get the cursor's x and y positions:*/
  pos = getCursorPos(e);
  /*calculate the position of the lens:*/
  x = pos.x - (lens.offsetWidth / 2);
  y = pos.y - (lens.offsetHeight / 2);
  /*prevent the lens from being positioned outside the image:*/
  if (x > img.width - lens.offsetWidth) {x = img.width - lens.offsetWidth;}
  if (x < 0) {x = 0;}
  if (y > img.height - lens.offsetHeight) {y = img.height - lens.offsetHeight;}
  if (y < 0) {y = 0;}
  /*set the position of the lens:*/
  lens.style.left = x + "px";
  lens.style.top = y + "px";
  /*display what the lens "sees":*/
  result.style.backgroundPosition = "-" + (x * cx) + "px -" + (y * cy) + "px";
 }
 function getCursorPos(e) {
  var a, x = 0, y = 0;
  e = e || window.event;
    /*get the x and y positions of the image:*/
  a = img.getBoundingClientRect();
   /*calculate the cursor's x and y coordinates, relative to the image:*/
  x = e.pageX - a.left;
  y = e.pageY - a.top;
    /*consider any page scrolling:*/
  x = x - window.pageXOffset;
  y = y - window.pageYOffset;
  return {x : x, y : y};
 }
}

Код Html,

<div class="container">



<div class="grosse-bild">
  <div class="kleine-fenster" id="myresult" > 
    <img src="/kalamulur/Taschen-&-Rucksäcke/Rucksäcke/fenster/photo/113.jpg" width=280 height=280 class="window" id="myimage">
  </div>  
 </div>
</div>

Здесь , чтобы показать это ..

Проблема этого кода в том, что он ничего не делает ...

Может кто-нибудь помочь и сказать мне, где моя ошибка?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...