Files
giao_dien_web_mau/demo-mevabe-1/assets/js/main.js

190 lines
5.8 KiB
JavaScript
Raw Normal View History

2023-03-23 10:35:24 +07:00
function run_carousel(holder, item, margins, navs, dot) {
$(holder).owlCarousel({
margin: margins,
lazyLoad: true,
loop: false,
autoplay: false,
autoplayTimeout: 4000,
autoplaySpeed: 1500,
autoplayHoverPause: true,
dots: dot,
nav: navs,
navText: ['<i class="fa fa-angle-left" aria-hidden="true"></i>', '<i class="fa fa-angle-right" aria-hidden="true"></i>'],
items: item,
});
}
$(document).ready(function () {
// slide trang chu
$("#js-slider-home").owlCarousel({
items: 1,
loop: true,
autoplay: true,
dotsSpeed: 1000,
navSpeed: 1000,
dots: false,
nav: true,
navText: ['<i class="fa fa-angle-left" aria-hidden="true"></i>', '<i class="fa fa-angle-right" aria-hidden="true"></i>'],
margin: 10,
lazyLoad: true
});
run_carousel($('#js-slider-deal'), 4, 10, true, false)
run_carousel($('#js-slider-feeback'), 3, 10, true, false)
run_carousel($('#js-slider-brand'), 8, 10, false, false)
})
function GetCount(ddate, iid) {
amount = ddate //calc milliseconds between dates
hours = 0;
mins = 0;
secs = 0;
out = "";
secs = Math.floor(amount % 60);
mins = Math.floor((amount % (60 * 60) / 60));
hours = Math.floor((amount / (60 * 60 * 24) / (60 * 60)));
out += "<div class='item-time'><b> " + (hours <= 9 ? '0' : '') + hours + " </b></div>";
out += "<div class='item-time'><b> " + (mins <= 9 ? '0' : '') + mins + " </b></div>";
out += "<div class='item-time'><b> " + (secs <= 9 ? '0' : '') + secs + " </b></div>";
//out = out.substr(0, out.length - 2);
$(iid).html(out)
setTimeout(function () {
GetCount(ddate - 1, iid)
}, 1000);
}
function countDown(iid) {
var now = new Date();
var end = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1);
// Tính khoảng cách thời gian giữa hai thời điểm
var distance = end - now;
// Cập nhật thời gian đếm ngược mỗi giây
var timer = setInterval(function () {
distance -= 1000;
var hours = Math.floor((distance / (1000 * 60 * 60)) % 24);
var minutes = Math.floor((distance / 1000 / 60) % 60);
var seconds = Math.floor((distance / 1000) % 60);
// Hiển thị thời gian đếm ngược trên trang web của bạn
$(iid).html("<div class='item-time'><b> " + (hours <= 9 ? '0' : '') + hours + " </b></div><div class='item-time'><b> " + (minutes <= 9 ? '0' : '') + minutes + " </b></div><div class='item-time'><b> " + (seconds <= 9 ? '0' : '') + seconds + " </b></div>");
}, 1000);
}
countDown($('.js-item-deal-time'))
const MIN_PAGE_PRICE = parseInt('0');
const MAX_PAGE_PRICE = parseInt('229999000');
var current_min = parseInt('0');
var current_max = parseInt('229999000');
$(document).ready(function () {
$('.min-price-filter').html(formatCurrency(current_min) + ' đ');
$('.max-price-filter').html(formatCurrency(current_max) + ' đ');
$('#input-min-price-filter').val(formatCurrency(current_min))
$('#input-max-price-filter').val(formatCurrency(current_max));
var options = {
range: true,
min: MIN_PAGE_PRICE,
max: MAX_PAGE_PRICE,
values: [current_min, current_max],
step: 5,
slide: function (event, ui) {
var min = Math.floor(ui.values[0]);
$('.min-price-filter').html(formatCurrency(min) + ' đ');
$('#input-min-price-filter').html(formatCurrency(min));
var max = Math.floor(ui.values[1]);
$('.max-price-filter').html(formatCurrency(max) + ' đ');
$('#input-max-price-filter').html(formatCurrency(max));
},
};
$("#slider-range").slider(options);
})
function formatCurrency(a) {
var b = parseFloat(a).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1.").toString();
var len = b.length;
b = b.substring(0, len - 3);
return b;
}
function finterPriceSli() {
var getMinPriceString = $('#input-min-price-filter').val();
var getMaxPriceString = $('#input-max-price-filter').val();
var getMinPrice = parseInt(getMinPriceString.replace(/\./g, ''));
var getMaxPrice = parseInt(getMaxPriceString.replace(/\./g, ''));
var textMinPrice = 'trieu';
var textMaxPrice = 'trieu';
if (getMinPrice < 1000000) {
var minPrice = Math.floor(getMinPrice / 1000);
textMinPrice = 'ngan';
} else {
var minPrice = Math.floor(getMinPrice / 1000000);
}
if (getMaxPrice < 1000000) {
var maxPrice = Math.round(getMaxPrice / 1000);
textMaxPrice = 'ngan';
} else {
var maxPrice = Math.round(getMaxPrice / 1000000);
}
window.location.href = '?p=' + minPrice + textMinPrice + '-' + maxPrice + textMaxPrice;
}
$(".js-title-filter").click(function () {
$(this).parents(".item-filter").toggleClass("active");
});
$('[data-fancybox="gallery"]').fancybox({
thumbs: {
autoStart: true
},
loop: true
});
$("#sync2 .item-thumbnail").click(function () {
event.preventDefault();
$(".item-thumbnail").removeClass("active");
$(this).addClass("active");
var src = $(this).find("a").attr("href");
$("#sync1 a").attr("href", src);
$("#sync1 img").attr("src", src);
return false;
});
$("#sync2").owlCarousel({
items: 4,
margin: 10,
dots: false,
nav: true,
autoHeight: true,
navText: ['<i class="fa fa-angle-left" aria-hidden="true"></i>', '<i class="fa fa-angle-right" aria-hidden="true"></i>'],
});
$("#title_tab_scroll_pro a").click(function () {
$("#title_tab_scroll_pro a").removeClass("active");
$(this).addClass("active");
var idTab = $(this).attr('href');
$('.content-tab').removeClass('active');
$(idTab).addClass('active')
return false;
});