A
A
Artem2021-06-21 13:08:44
JavaScript
Artem, 2021-06-21 13:08:44

What to do so that the code behaves the same in different browsers?

While working on the local server 'openserver' in 'firefox' everything was displayed correctly without any friezes. I decided to check the layout in other browsers 'googlechrome' , 'opera' , 'IE' where I found a delay and friezes during the processing of 'js' code.
Perhaps I'm using the wrong approach in writing the code (it's strange, but then why does 'firefox' show everything without problems). I ask for advice in this case.

; $(document).ready(function () {
    fix = [];
    val = [];
    sh1 = $(window).height();
    checkarrow(sh1);
    function checkarrow(sh1) { // при запуске страницы без скрола
        if ($(this).scrollTop() == 0) {
            $(".header-fixed-arrow").css({ 'position': 'fixed', 'left': '2px', 'transform': 'rotateZ(180deg)', 'top': '12px' });
            val.pop();
            val.push(5);
        }
        if ($(this).scrollTop() + sh1 <= 3170 && val == 0) {
            $(".header-fixed-arrow").css({ 'transition': 'linear 1s', 'position': 'fixed', 'top': 'unset', 'left': '2px', 'bottom': '56px' });
            val.pop();
            val.push(1);
        }
        heigst = $(".fb-wrap").offset().top;
        sh1 = $(window).height();
        sh2 = $('.header-fixed-question').outerHeight();
        sh3 = $('.header-fixed-arrow').outerHeight();
        if ($(this).scrollTop() + sh1 - 8.5 > heigst + sh3 / 2 + sh2) {
            $(".header-fixed-arrow").css({ 'transform': 'none', 'position': 'absolute', 'top': '' + heigst - sh3 / 2 + 'px' });
            fix.pop();
            fix.push(3171);
            val.pop();
            val.push(1);
        }
    };
    $(window).scroll(function () { // Во время скрола
        nt1 = sh1 - 108;
        value1();
        function value1() {
            if ($(this).scrollTop() == 0) {
                $(".header-fixed-arrow").css({ 'transition': 'linear 1s' });
                fix.pop();
                fix.push(5);
                if (val == 1) {
                    $(".header-fixed-arrow").css({ 'transform': 'translateY(-' + nt1 + 'px) rotateZ(180deg)' });
                    return;
                }
                $(".header-fixed-arrow").css({ 'transform': 'translateY(0px) rotateZ(180deg)' });
            }
        }
        value2(nt1);
        function value2(nt1) {
            if ($(this).scrollTop() > 1 && $(this).scrollTop() + (Number(fix.join())) < 3171) {
                $(".header-fixed-arrow").css({ 'transition': 'linear 1s' });
                if (val == 1) {
                    $(".header-fixed-arrow").css({ 'transform': 'translateY(0px) rotateZ(0deg)' });
                    return;
                }
                $(".header-fixed-arrow").css({ 'transform': 'translateY(' + nt1 + 'px) rotateZ(0deg)' });
            }
        }
        heigst = $(".fb-wrap").offset().top;
        sh2 = $('.header-fixed-question').outerHeight();
        sh3 = $('.header-fixed-arrow').outerHeight();
        if ($(this).scrollTop() + sh1 - 8.5 < heigst + sh3 / 2 + sh2 && fix == 3171) {
            $(".header-fixed-arrow").css({ 'transition': 'linear 1s', 'position': 'fixed', 'top': 'unset', 'left': '2px', 'bottom': '56px' });
        }
        if ($(this).scrollTop() + sh1 - 8.5 > heigst + sh3 / 2 + sh2) {
            $(".header-fixed-arrow").css({ 'transition': 'linear 0s', 'transform': 'none', 'position': 'absolute', 'top': '' + heigst - sh3 / 2 + 'px' });
            fix.pop();
            fix.push(3171);
            val.pop();
            val.push(1);
        }
    });
    $('.header-fixed-arrow').click(function () {
        if ($(window).scrollTop() == 0) {
            $('html, body').animate({ scrollTop: 2050 }, 1100);
        };
        if ($(window).scrollTop() >= 1) {
            $('html, body').animate({ scrollTop: 0 }, 1100);
        }
    })
});

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question