Reid  Rohan

Reid Rohan

1618575780

Vuetify — Overlays

Vuetify is a popular UI framework for Vue apps.

In this article, we’ll look at how to work with the Vuetify framework.

Overlays

We can add overlays with the v-overlay component.

It’s used to provide emphasis on particular elements or parts of it.

And it’s useful for signaling state change.

We can create one by writing:

<template>
  <v-row align="center" justify="center">
    <v-card height="300" width="250">
      <v-row justify="center">
        <v-btn color="success" class="mt-12" @click="overlay = !overlay">Show Overlay</v-btn>
        <v-overlay :absolute="absolute" :value="overlay">
          <v-btn color="success" @click="overlay = false">Hide Overlay</v-btn>
        </v-overlay>
      </v-row>
    </v-card>
  </v-row>
</template>

#technology #programming #javascript

What is GEEK

Buddha Community

Vuetify — Overlays
CODE VN

CODE VN

1657880700

Cách tạo hiệu ứng thu phóng hình ảnh sản phẩm bằng JavaScript

Trong hướng dẫn này, chúng ta sẽ học cách tạo hiệu ứng thu phóng hình ảnh sản phẩm bằng JavaScript. Để tạo hiệu ứng thu phóng hình ảnh sản phẩm bằng JavaScript. Bạn cần tạo ba tệp HTML, CSS & JavaScript.

1: Đầu tiên, tạo một tệp HTML

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Product Image Zoom</title>
    <!-- Stylesheet -->
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <div class="image-container" id="image-container">
      <img src="shoe-img.jpg" id="product-image" alt="shoe" />
    </div>
    <div id="mouse-overlay"></div>
    <div id="overlay"></div>
    <!-- Script -->
    <script src="script.js"></script>
  </body>
</html>

 

2: Thứ hai, tạo một tệp CSS

 

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}
.image-container {
  width: 30%;
  margin: 5% 0 0 5%;
}
img {
  max-width: 100%;
}
#overlay {
  display: none;
  background: url("shoe-img.jpg");
  position: absolute;
  width: 25%;
  height: 35%;
  margin-top: -30%;
  margin-left: 50%;
  border: 2px solid #555;
  z-index: 1000;
  background-repeat: no-repeat;
}
#mouse-overlay {
  cursor: zoom-in;
  position: absolute;
  width: 2em;
  height: 2em;
  transform: translate(-50%, -50%);
  background-color: rgba(245, 245, 245, 0.6);
  border-radius: 50%;
}
@media only screen and (max-width: 768px) {
  .image-container {
    width: 55%;
  }
  #overlay {
    margin-left: 70%;
    width: 25%;
    height: 15%;
  }
}

 

3: Cuối cùng, tạo một tệp JavaScript

 

//Initial References
let imageContainer = document.getElementById("image-container");
let productImage = document.getElementById("product-image");
let overlay = document.getElementById("overlay");
let mouseOverlay = document.getElementById("mouse-overlay");

//events object(stores events for touch,mouse)
let events = {
  mouse: {
    move: "mousemove",
  },
  touch: {
    move: "touchmove",
  },
};

//initially blank
let deviceType = "";

//Checks for device type
function isTouchDevice() {
  try {
    //We try to create touch event (it would fail for desktops and throw error)
    deviceType = "touch";
    document.createEvent("TouchEvent");
    return true;
  } catch (e) {
    deviceType = "mouse";
    return false;
  }
}

//hides overlay
const hideElement = () => {
  overlay.style.display = "none";
  mouseOverlay.style.display = "none";
};

//Check device so that deviceType variable is set to touch or mouse
isTouchDevice();

/*In addEventListener we use the events object to set the event so deviceType would be set to touch or mouse since we called 'isTouchDevice()' above
E.g:
if deviceType = "mouse" => the statement for event would be events[mouse].move which equals to mousemove.
if deviceType = "touch" => the statement for event would be events[touch].move which equals to touchstart.
*/

imageContainer.addEventListener(events[deviceType].move, (e) => {
  //Try, catch to avoid any errors for touch screens
  try {
    //pageX and pageY return the position of client's cursor from top left pf screen
    var x = !isTouchDevice() ? e.pageX : e.touches[0].pageX;
    var y = !isTouchDevice() ? e.pageY : e.touches[0].pageY;
  } catch (e) {}
  //get image height and width
  let imageWidth = imageContainer.offsetWidth;
  let imageHeight = imageContainer.offsetHeight;

  //check if mouse goes out of image container
  if (
    imageWidth - (x - imageContainer.offsetLeft) < 15 ||
    x - imageContainer.offsetLeft < 15 ||
    imageHeight - (y - imageContainer.offsetTop) < 15 ||
    y - imageContainer.offsetTop < 15
  ) {
    hideElement();
  } else {
    overlay.style.display = "block";
    mouseOverlay.style.display = "inline-block";
  }

  var posX = ((x - imageContainer.offsetLeft) / imageWidth).toFixed(4) * 100;
  var posY = ((y - imageContainer.offsetTop) / imageHeight).toFixed(4) * 100;

  //set background position to above obtained values
  overlay.style.backgroundPosition = posX + "%" + posY + "%";

  //move the overlay with cursor
  mouseOverlay.style.top = y + "px";
  mouseOverlay.style.left = x + "px";
});

Bây giờ bạn đã tạo thành công hiệu ứng thu phóng hình ảnh sản phẩm bằng JavaScript. 

Chúc bạn mã hóa vui vẻ !!!

中條 美冬

1657895340

JavaScriptを使用して製品画像のズーム効果を作成する方法

このガイドでは、JavaScriptを使用して商品画像のズーム効果を作成する方法を学習します。JavaScriptを使用して製品画像のズーム効果を作成します。HTML、CSS、JavaScriptの3つのファイルを作成する必要があります。

1:まず、HTMLファイルを作成します

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Product Image Zoom</title>
    <!-- Stylesheet -->
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <div class="image-container" id="image-container">
      <img src="shoe-img.jpg" id="product-image" alt="shoe" />
    </div>
    <div id="mouse-overlay"></div>
    <div id="overlay"></div>
    <!-- Script -->
    <script src="script.js"></script>
  </body>
</html>

 

2:次に、CSSファイルを作成します

 

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}
.image-container {
  width: 30%;
  margin: 5% 0 0 5%;
}
img {
  max-width: 100%;
}
#overlay {
  display: none;
  background: url("shoe-img.jpg");
  position: absolute;
  width: 25%;
  height: 35%;
  margin-top: -30%;
  margin-left: 50%;
  border: 2px solid #555;
  z-index: 1000;
  background-repeat: no-repeat;
}
#mouse-overlay {
  cursor: zoom-in;
  position: absolute;
  width: 2em;
  height: 2em;
  transform: translate(-50%, -50%);
  background-color: rgba(245, 245, 245, 0.6);
  border-radius: 50%;
}
@media only screen and (max-width: 768px) {
  .image-container {
    width: 55%;
  }
  #overlay {
    margin-left: 70%;
    width: 25%;
    height: 15%;
  }
}

 

3:最後に、JavaScriptファイルを作成します

 

//Initial References
let imageContainer = document.getElementById("image-container");
let productImage = document.getElementById("product-image");
let overlay = document.getElementById("overlay");
let mouseOverlay = document.getElementById("mouse-overlay");

//events object(stores events for touch,mouse)
let events = {
  mouse: {
    move: "mousemove",
  },
  touch: {
    move: "touchmove",
  },
};

//initially blank
let deviceType = "";

//Checks for device type
function isTouchDevice() {
  try {
    //We try to create touch event (it would fail for desktops and throw error)
    deviceType = "touch";
    document.createEvent("TouchEvent");
    return true;
  } catch (e) {
    deviceType = "mouse";
    return false;
  }
}

//hides overlay
const hideElement = () => {
  overlay.style.display = "none";
  mouseOverlay.style.display = "none";
};

//Check device so that deviceType variable is set to touch or mouse
isTouchDevice();

/*In addEventListener we use the events object to set the event so deviceType would be set to touch or mouse since we called 'isTouchDevice()' above
E.g:
if deviceType = "mouse" => the statement for event would be events[mouse].move which equals to mousemove.
if deviceType = "touch" => the statement for event would be events[touch].move which equals to touchstart.
*/

imageContainer.addEventListener(events[deviceType].move, (e) => {
  //Try, catch to avoid any errors for touch screens
  try {
    //pageX and pageY return the position of client's cursor from top left pf screen
    var x = !isTouchDevice() ? e.pageX : e.touches[0].pageX;
    var y = !isTouchDevice() ? e.pageY : e.touches[0].pageY;
  } catch (e) {}
  //get image height and width
  let imageWidth = imageContainer.offsetWidth;
  let imageHeight = imageContainer.offsetHeight;

  //check if mouse goes out of image container
  if (
    imageWidth - (x - imageContainer.offsetLeft) < 15 ||
    x - imageContainer.offsetLeft < 15 ||
    imageHeight - (y - imageContainer.offsetTop) < 15 ||
    y - imageContainer.offsetTop < 15
  ) {
    hideElement();
  } else {
    overlay.style.display = "block";
    mouseOverlay.style.display = "inline-block";
  }

  var posX = ((x - imageContainer.offsetLeft) / imageWidth).toFixed(4) * 100;
  var posY = ((y - imageContainer.offsetTop) / imageHeight).toFixed(4) * 100;

  //set background position to above obtained values
  overlay.style.backgroundPosition = posX + "%" + posY + "%";

  //move the overlay with cursor
  mouseOverlay.style.top = y + "px";
  mouseOverlay.style.left = x + "px";
});

これで、JavaScriptを使用して商品画像のズーム効果を正常に作成できました。 

ハッピーコーディング!!!

Como criar um efeito de zoom de imagem de produto usando JavaScript

Neste guia, aprenderemos como criar um efeito de zoom na imagem do produto usando JavaScript. Para criar um efeito de zoom na imagem do produto usando JavaScript. Você precisa criar três arquivos HTML, CSS e JavaScript.

1: Primeiro, crie um arquivo HTML

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Product Image Zoom</title>
    <!-- Stylesheet -->
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <div class="image-container" id="image-container">
      <img src="shoe-img.jpg" id="product-image" alt="shoe" />
    </div>
    <div id="mouse-overlay"></div>
    <div id="overlay"></div>
    <!-- Script -->
    <script src="script.js"></script>
  </body>
</html>

 

2: Em segundo lugar, crie um arquivo CSS

 

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}
.image-container {
  width: 30%;
  margin: 5% 0 0 5%;
}
img {
  max-width: 100%;
}
#overlay {
  display: none;
  background: url("shoe-img.jpg");
  position: absolute;
  width: 25%;
  height: 35%;
  margin-top: -30%;
  margin-left: 50%;
  border: 2px solid #555;
  z-index: 1000;
  background-repeat: no-repeat;
}
#mouse-overlay {
  cursor: zoom-in;
  position: absolute;
  width: 2em;
  height: 2em;
  transform: translate(-50%, -50%);
  background-color: rgba(245, 245, 245, 0.6);
  border-radius: 50%;
}
@media only screen and (max-width: 768px) {
  .image-container {
    width: 55%;
  }
  #overlay {
    margin-left: 70%;
    width: 25%;
    height: 15%;
  }
}

 

3: Por último, crie um arquivo JavaScript

 

//Initial References
let imageContainer = document.getElementById("image-container");
let productImage = document.getElementById("product-image");
let overlay = document.getElementById("overlay");
let mouseOverlay = document.getElementById("mouse-overlay");

//events object(stores events for touch,mouse)
let events = {
  mouse: {
    move: "mousemove",
  },
  touch: {
    move: "touchmove",
  },
};

//initially blank
let deviceType = "";

//Checks for device type
function isTouchDevice() {
  try {
    //We try to create touch event (it would fail for desktops and throw error)
    deviceType = "touch";
    document.createEvent("TouchEvent");
    return true;
  } catch (e) {
    deviceType = "mouse";
    return false;
  }
}

//hides overlay
const hideElement = () => {
  overlay.style.display = "none";
  mouseOverlay.style.display = "none";
};

//Check device so that deviceType variable is set to touch or mouse
isTouchDevice();

/*In addEventListener we use the events object to set the event so deviceType would be set to touch or mouse since we called 'isTouchDevice()' above
E.g:
if deviceType = "mouse" => the statement for event would be events[mouse].move which equals to mousemove.
if deviceType = "touch" => the statement for event would be events[touch].move which equals to touchstart.
*/

imageContainer.addEventListener(events[deviceType].move, (e) => {
  //Try, catch to avoid any errors for touch screens
  try {
    //pageX and pageY return the position of client's cursor from top left pf screen
    var x = !isTouchDevice() ? e.pageX : e.touches[0].pageX;
    var y = !isTouchDevice() ? e.pageY : e.touches[0].pageY;
  } catch (e) {}
  //get image height and width
  let imageWidth = imageContainer.offsetWidth;
  let imageHeight = imageContainer.offsetHeight;

  //check if mouse goes out of image container
  if (
    imageWidth - (x - imageContainer.offsetLeft) < 15 ||
    x - imageContainer.offsetLeft < 15 ||
    imageHeight - (y - imageContainer.offsetTop) < 15 ||
    y - imageContainer.offsetTop < 15
  ) {
    hideElement();
  } else {
    overlay.style.display = "block";
    mouseOverlay.style.display = "inline-block";
  }

  var posX = ((x - imageContainer.offsetLeft) / imageWidth).toFixed(4) * 100;
  var posY = ((y - imageContainer.offsetTop) / imageHeight).toFixed(4) * 100;

  //set background position to above obtained values
  overlay.style.backgroundPosition = posX + "%" + posY + "%";

  //move the overlay with cursor
  mouseOverlay.style.top = y + "px";
  mouseOverlay.style.left = x + "px";
});

Agora você criou com sucesso um efeito de zoom da imagem do produto usando JavaScript. 

Boa Codificação!!!

Felix Kling

Felix Kling

1663918478

Product Image Zoom Effect with HTML, CSS and JavaScript

In this tutorial, you'll learn how to create a product image zoom effect with HTML, CSS and JavaScript. Learn how you can zoom a specific part of image just like those used on e-commerce websites using HTML, CSS & JS.

HTML:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Product Image Zoom</title>
    <!-- Stylesheet -->
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <div class="image-container" id="image-container">
      <img src="shoe-img.jpg" id="product-image" alt="shoe" />
    </div>
    <div id="mouse-overlay"></div>
    <div id="overlay"></div>
    <!-- Script -->
    <script src="script.js"></script>
  </body>
</html>

CSS:

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}
.image-container {
  width: 30%;
  margin: 5% 0 0 5%;
}
img {
  max-width: 100%;
}
#overlay {
  display: none;
  background: url("shoe-img.jpg");
  position: absolute;
  width: 25%;
  height: 35%;
  margin-top: -30%;
  margin-left: 50%;
  border: 2px solid #555;
  z-index: 1000;
  background-repeat: no-repeat;
}
#mouse-overlay {
  cursor: zoom-in;
  position: absolute;
  width: 2em;
  height: 2em;
  transform: translate(-50%, -50%);
  background-color: rgba(245, 245, 245, 0.6);
  border-radius: 50%;
}
@media only screen and (max-width: 768px) {
  .image-container {
    width: 55%;
  }
  #overlay {
    margin-left: 70%;
    width: 25%;
    height: 15%;
  }
}

Javascript:

//Initial References
let imageContainer = document.getElementById("image-container");
let productImage = document.getElementById("product-image");
let overlay = document.getElementById("overlay");
let mouseOverlay = document.getElementById("mouse-overlay");

//events object(stores events for touch,mouse)
let events = {
  mouse: {
    move: "mousemove",
  },
  touch: {
    move: "touchmove",
  },
};

//initially blank
let deviceType = "";

//Checks for device type
function isTouchDevice() {
  try {
    //We try to create touch event (it would fail for desktops and throw error)
    deviceType = "touch";
    document.createEvent("TouchEvent");
    return true;
  } catch (e) {
    deviceType = "mouse";
    return false;
  }
}

//hides overlay
const hideElement = () => {
  overlay.style.display = "none";
  mouseOverlay.style.display = "none";
};

//Check device so that deviceType variable is set to touch or mouse
isTouchDevice();

/*In addEventListener we use the events object to set the event so deviceType would be set to touch or mouse since we called 'isTouchDevice()' above
E.g:
if deviceType = "mouse" => the statement for event would be events[mouse].move which equals to mousemove.
if deviceType = "touch" => the statement for event would be events[touch].move which equals to touchstart.
*/

imageContainer.addEventListener(events[deviceType].move, (e) => {
  //Try, catch to avoid any errors for touch screens
  try {
    //pageX and pageY return the position of client's cursor from top left pf screen
    var x = !isTouchDevice() ? e.pageX : e.touches[0].pageX;
    var y = !isTouchDevice() ? e.pageY : e.touches[0].pageY;
  } catch (e) {}
  //get image height and width
  let imageWidth = imageContainer.offsetWidth;
  let imageHeight = imageContainer.offsetHeight;

  //check if mouse goes out of image container
  if (
    imageWidth - (x - imageContainer.offsetLeft) < 15 ||
    x - imageContainer.offsetLeft < 15 ||
    imageHeight - (y - imageContainer.offsetTop) < 15 ||
    y - imageContainer.offsetTop < 15
  ) {
    hideElement();
  } else {
    overlay.style.display = "block";
    mouseOverlay.style.display = "inline-block";
  }

  var posX = ((x - imageContainer.offsetLeft) / imageWidth).toFixed(4) * 100;
  var posY = ((y - imageContainer.offsetTop) / imageHeight).toFixed(4) * 100;

  //set background position to above obtained values
  overlay.style.backgroundPosition = posX + "%" + posY + "%";

  //move the overlay with cursor
  mouseOverlay.style.top = y + "px";
  mouseOverlay.style.left = x + "px";
});

Related Videos

Image Zoom Effect | Product Gallery

Product Card Design With Image Zoom Effect On Hover Using HTML/CSS/JQUERY

#html #css #javascript

Duck Hwan

1657888022

JavaScript를 사용하여 제품 이미지 확대 효과를 만드는 방법

이 가이드에서는 JavaScript를 사용하여 제품 이미지 확대 효과를 만드는 방법을 배웁니다. JavaScript를 사용하여 제품 이미지 확대/축소 효과를 만들려면. HTML, CSS 및 JavaScript의 세 가지 파일을 만들어야 합니다.

1: 먼저 HTML 파일을 만듭니다.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Product Image Zoom</title>
    <!-- Stylesheet -->
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <div class="image-container" id="image-container">
      <img src="shoe-img.jpg" id="product-image" alt="shoe" />
    </div>
    <div id="mouse-overlay"></div>
    <div id="overlay"></div>
    <!-- Script -->
    <script src="script.js"></script>
  </body>
</html>

 

2: 두 번째, CSS 파일 생성

 

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}
.image-container {
  width: 30%;
  margin: 5% 0 0 5%;
}
img {
  max-width: 100%;
}
#overlay {
  display: none;
  background: url("shoe-img.jpg");
  position: absolute;
  width: 25%;
  height: 35%;
  margin-top: -30%;
  margin-left: 50%;
  border: 2px solid #555;
  z-index: 1000;
  background-repeat: no-repeat;
}
#mouse-overlay {
  cursor: zoom-in;
  position: absolute;
  width: 2em;
  height: 2em;
  transform: translate(-50%, -50%);
  background-color: rgba(245, 245, 245, 0.6);
  border-radius: 50%;
}
@media only screen and (max-width: 768px) {
  .image-container {
    width: 55%;
  }
  #overlay {
    margin-left: 70%;
    width: 25%;
    height: 15%;
  }
}

 

3: 마지막으로 JavaScript 파일 생성

 

//Initial References
let imageContainer = document.getElementById("image-container");
let productImage = document.getElementById("product-image");
let overlay = document.getElementById("overlay");
let mouseOverlay = document.getElementById("mouse-overlay");

//events object(stores events for touch,mouse)
let events = {
  mouse: {
    move: "mousemove",
  },
  touch: {
    move: "touchmove",
  },
};

//initially blank
let deviceType = "";

//Checks for device type
function isTouchDevice() {
  try {
    //We try to create touch event (it would fail for desktops and throw error)
    deviceType = "touch";
    document.createEvent("TouchEvent");
    return true;
  } catch (e) {
    deviceType = "mouse";
    return false;
  }
}

//hides overlay
const hideElement = () => {
  overlay.style.display = "none";
  mouseOverlay.style.display = "none";
};

//Check device so that deviceType variable is set to touch or mouse
isTouchDevice();

/*In addEventListener we use the events object to set the event so deviceType would be set to touch or mouse since we called 'isTouchDevice()' above
E.g:
if deviceType = "mouse" => the statement for event would be events[mouse].move which equals to mousemove.
if deviceType = "touch" => the statement for event would be events[touch].move which equals to touchstart.
*/

imageContainer.addEventListener(events[deviceType].move, (e) => {
  //Try, catch to avoid any errors for touch screens
  try {
    //pageX and pageY return the position of client's cursor from top left pf screen
    var x = !isTouchDevice() ? e.pageX : e.touches[0].pageX;
    var y = !isTouchDevice() ? e.pageY : e.touches[0].pageY;
  } catch (e) {}
  //get image height and width
  let imageWidth = imageContainer.offsetWidth;
  let imageHeight = imageContainer.offsetHeight;

  //check if mouse goes out of image container
  if (
    imageWidth - (x - imageContainer.offsetLeft) < 15 ||
    x - imageContainer.offsetLeft < 15 ||
    imageHeight - (y - imageContainer.offsetTop) < 15 ||
    y - imageContainer.offsetTop < 15
  ) {
    hideElement();
  } else {
    overlay.style.display = "block";
    mouseOverlay.style.display = "inline-block";
  }

  var posX = ((x - imageContainer.offsetLeft) / imageWidth).toFixed(4) * 100;
  var posY = ((y - imageContainer.offsetTop) / imageHeight).toFixed(4) * 100;

  //set background position to above obtained values
  overlay.style.backgroundPosition = posX + "%" + posY + "%";

  //move the overlay with cursor
  mouseOverlay.style.top = y + "px";
  mouseOverlay.style.left = x + "px";
});

이제 JavaScript를 사용하여 제품 이미지 확대/축소 효과를 성공적으로 만들었습니다. 

즐거운 코딩!!!