mirror of https://gitee.com/topnuomi/zxf
优化js
This commit is contained in:
parent
f733b117fd
commit
c3d135bb54
48
js/main.js
48
js/main.js
|
@ -9,6 +9,29 @@ let isClose = true,
|
||||||
headerMenuBtn = $('.btn-img'),
|
headerMenuBtn = $('.btn-img'),
|
||||||
currentRem = 0;
|
currentRem = 0;
|
||||||
|
|
||||||
|
function getRem() {
|
||||||
|
let windowWidth = window.innerWidth
|
||||||
|
return windowWidth * (100 / (windowWidth > 768 ? 1920 : 750));
|
||||||
|
}
|
||||||
|
function rszcal() {
|
||||||
|
currentRem = getRem();
|
||||||
|
$('html').css('font-size', currentRem + "px");
|
||||||
|
}
|
||||||
|
|
||||||
|
function headerEffect() {
|
||||||
|
let t = $(document).scrollTop(), flag;
|
||||||
|
if ($(window).width() > 768) {
|
||||||
|
flag = t > 4 * currentRem;
|
||||||
|
} else {
|
||||||
|
flag = t > 0.6 * currentRem;
|
||||||
|
}
|
||||||
|
if (flag) {
|
||||||
|
header.removeClass('style1').addClass('style2');
|
||||||
|
} else {
|
||||||
|
header.removeClass('style2').addClass('style1');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let t1;
|
let t1;
|
||||||
function showMenu() {
|
function showMenu() {
|
||||||
clearTimeout(t1);
|
clearTimeout(t1);
|
||||||
|
@ -34,32 +57,13 @@ function hideMenu() {
|
||||||
}
|
}
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
function getRem() {
|
|
||||||
let windowWidth = window.innerWidth
|
|
||||||
return windowWidth * (100 / (windowWidth > 768 ? 1920 : 750));
|
|
||||||
}
|
|
||||||
function rszcal() {
|
|
||||||
currentRem = getRem();
|
|
||||||
$('html').css('font-size', currentRem + "px");
|
|
||||||
}
|
|
||||||
$(window).resize(rszcal);
|
|
||||||
rszcal();
|
rszcal();
|
||||||
|
$(window).resize(rszcal);
|
||||||
|
$(window).scroll(headerEffect);
|
||||||
|
|
||||||
$('.header .menu-group').load('../common/header.html');
|
$('.header .menu-group').load('../common/header.html');
|
||||||
$('.footer').load('../common/footer.html');
|
$('.footer').load('../common/footer.html');
|
||||||
$(window).scroll(function () {
|
|
||||||
let t = $(document).scrollTop(), flag;
|
|
||||||
if ($(window).width() > 768) {
|
|
||||||
flag = t > 4 * currentRem;
|
|
||||||
} else {
|
|
||||||
flag = t > 0.6 * currentRem;
|
|
||||||
}
|
|
||||||
if (flag) {
|
|
||||||
header.removeClass('style1').addClass('style2');
|
|
||||||
} else {
|
|
||||||
header.removeClass('style2').addClass('style1');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
header.on('click', '.menu-btn', function () {
|
header.on('click', '.menu-btn', function () {
|
||||||
(isClose == true) ? showMenu() : hideMenu();
|
(isClose == true) ? showMenu() : hideMenu();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue