Hover over image and get zoom effect on another image using javascript?

Code breakdown:

This code has a main image (the big picture at top), and then smaller preview pictures under than main image. (Ignore the big picture at bottom as this is used to help visually troubleshoot the code).

  // Preview-img change on hover

  function setURL(newUrl) {
    var url = newUrl;
    return function () {
      document.getElementById('main-img').setAttribute('src', url);
    }
  }
  document.getElementById('preview-img-one').addEventListener('mouseover', setURL('https://rb.gy/1jca3j'));
  document.getElementById('preview-img-two').addEventListener('mouseover', setURL('https://rb.gy/st92i9'));
  document.getElementById('preview-img-three').addEventListener('mouseover', setURL('https://rb.gy/ntzcbd'));
  document.getElementById('preview-img-four').addEventListener('mouseover', setURL('https://shorturl.at/pJPX1'));
  document.getElementById('preview-img-five').addEventListener('mouseover', setURL('https://shorturl.at/lMUX6'));

  // Magnify glass

  function zoomIn(event) {
    var element = document.getElementById("mag-overlay");
    element.style.display = "inline-block";
    var posX = event.offsetX ? (event.offsetX) : event.pageX - img.offsetLeft;
    var posY = event.offsetY ? (event.offsetY) : event.pageY - img.offsetTop;
    element.style.backgroundPosition = (-posX * .9) + "px " + (-posY * .9) + "px";
 
    var element = document.getElementById("mag-overlay-two");
    element.style.display = "inline-block";
    var posX = event.offsetX ? (event.offsetX) : event.pageX - img.offsetLeft;
    var posY = event.offsetY ? (event.offsetY) : event.pageY - img.offsetTop;
    element.style.backgroundPosition = (-posX * .9) + "px " + (-posY * .9) + "px";
  }
  .product-preview-imgs-container-center {
    display: flex;
    justify-content: center;
    margin-top: 16px;
    width: 545.4px;
    height: 64px;
  }

  .preview-imgs-wrap {
    display: flex;
    justify-content: space-evenly;
    width: 352px;
    height: 64px;
  }

  #preview-img-one,
  #preview-img-two,
  #preview-img-three,
  #preview-img-four,
  #preview-img-five {
    width: 62.5667px;
    height: 62.5667px;
  }

  #preview-img-one:hover,
  #preview-img-two:hover,
  #preview-img-three:hover,
  #preview-img-four:hover,
  #preview-img-five:hover {
    border: 1px solid #191919;
    border-radius: 6px;
    width: 62.5667px;
    height: 62.5667px;
  }

  /* Magnifying Glass CSS */
  .main-img-container {
    width: 450.217px;
    height: 450.217px;
  }

  #main-img {
    width: 450.217px;
    height: 450.217px;
  }

  #main-img:hover {
    opacity: 0;
  }

  #mag-overlay {
    position: relative;
    left: -1px;
    bottom: 455px;
    width: 450.217px;
    height: 450.217px;
    display: inline-block;
    background-image: url("https://shorturl.at/qDN03");
    background-repeat: no-repeat;
    background-size: 175%;
    z-index: -1;
  }

  #mag-overlay-two {
    position: relative;
    left: -1px;
    bottom: 355px;
    width: 450.217px;
    height: 450.217px;
    display: inline-block;
    background-image: url("https://shorturl.at/qDN03");
    background-repeat: no-repeat;
    background-size: 175%;
    z-index: -1;
  }
  <div class="main-img-preview-img-wrap">
    <div class="main-img-container">
      <img id="main-img" onmousemove="zoomIn(event)" src="https://rb.gy/1jca3j">
      <div id="mag-overlay" onmousemove="zoomIn(event)"></div>
      <div id="mag-overlay-two" onmousemove="zoomIn(event)"></div>
    </div>
    <div class="product-preview-imgs-container-center">
      <div class="preview-imgs-wrap">
        <img id="preview-img-one" src="https://rb.gy/1jca3j" />
        <img id="preview-img-two" src="https://rb.gy/st92i9" />
        <img id="preview-img-three" src="https://rb.gy/ntzcbd" />
        <img id="preview-img-four" src="https://shorturl.at/pJPX1" />
        <img id="preview-img-five" src="https://shorturl.at/lMUX6" />
      </div>
    </div>
  </div>

What I want to accomplish:

What I want to happen is when the mouse hovers over each of the smaller preview pictures, the top main picture changes to the preview picture that has the mouse over it. I want to do this WITHOUT taking off the zoom effect, as the zoom effect is supposed to zoom in on each preview picture.

Sounds simple enough, but I’ve been struggling with this for days now.

What might work:

I’m assuming this part of the code needs a conditional statement like if..else to make it this work, which I’ve tried but have failed:

  function zoomIn(event) {
    var element = document.getElementById("mag-overlay");
    element.style.display = "inline-block";
    var posX = event.offsetX ? (event.offsetX) : event.pageX - img.offsetLeft;
    var posY = event.offsetY ? (event.offsetY) : event.pageY - img.offsetTop;
    element.style.backgroundPosition = (-posX * .9) + "px " + (-posY * .9) + "px";
  }

  function zoomIn(event) {
    var element = document.getElementById("mag-overlay-two");
    element.style.display = "inline-block";
    var posX = event.offsetX ? (event.offsetX) : event.pageX - img.offsetLeft;
    var posY = event.offsetY ? (event.offsetY) : event.pageY - img.offsetTop;
    element.style.backgroundPosition = (-posX * .9) + "px " + (-posY * .9) + "px";
  }

A visual of what I’m trying to implement:

I’m basically trying to copy the same effect aliexpress has on their website, which you can visually see here: https://shorturl.at/dkwKY

How can I achieve this with the code I have, or any other way using javascript? THANK YOU!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật