This commit is contained in:
2025-02-24 10:16:18 +07:00
parent d20a20684d
commit fe6ba5b1a0

View File

@@ -21,42 +21,41 @@
function HoverShowMenu() {
$("#js-menu-big .box-item .item").on("mousemove", function () {
let $checkMenu = $('#js-menu-big').hasClass('active');
if ($checkMenu) {
let $hoverMenu = $('#js-hover-menu');
let $this = $(this).parents('.box-item');
let $hoverContent = $this.find('.hover-menu');
const $menuBig = $('#js-menu-big');
const $hoverMenu = $('#js-hover-menu');
$menuBig.find('.box-item .item').on('mousemove', function () {
if ($menuBig.hasClass('active')) {
const $parentItem = $(this).closest('.box-item');
const $hoverContent = $parentItem.find('.hover-menu');
if ($hoverContent.length) {
let offset = $this.offset();
let x = offset.left + $("#js-menu-big").width();
let y = offset.top;
const offset = $parentItem.offset();
const menuWidth = $menuBig.width();
const hoverHeight = $hoverContent.outerHeight();
const windowHeight = $(window).height();
const maxY = $(window).scrollTop() + windowHeight;
// Kiểm tra nếu hoverContent bị tràn màn hình ở dưới
let hoverHeight = $hoverContent.outerHeight();
let windowHeight = $(window).height();
let maxY = $(window).scrollTop() + windowHeight; // Vị trí Y tối đa có thể hiển thị
let newY = y;
let posX = offset.left + menuWidth;
let posY = offset.top;
if (y + hoverHeight > maxY) {
newY = maxY - hoverHeight - 10;
if (posY + hoverHeight > maxY) {
posY = maxY - hoverHeight - 10;
}
$hoverMenu.addClass('active')
.html($hoverContent.html())
.css({ left: x, top: newY });
.css({ left: posX, top: posY });
}
}
});
$("#js-hover-menu").on("mouseleave", function () {
$("#js-hover-menu").removeClass("active");
$hoverMenu.on('mouseleave', function () {
$hoverMenu.removeClass('active');
});
}
function formatCurrency(a) {
var b = parseFloat(a).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1.").toString();
var len = b.length;