Z
Z
zhyshy2017-11-02 11:24:55
JavaScript
zhyshy, 2017-11-02 11:24:55

Why doesn't the script fire in IE11 on load, but only on window resize?

Good afternoon!

There is a site with horizontal scrolling. The site is navigated using the jquery mousewheel (turn the wheel down - the site scrolls horizontally).

For everything to work correctly, the main DIV container must be given a fixed width, which consists of the sum of all child DIVs (they can be either fixed or equal to the width of the visitor's screen).
All this is done using a script:

// Считаем ширину экрана
            var smWidth = (function () {
                $('.full').css('width', $(window).width());  // Задаем элементам с данным классом ширину равную экрану
            });
            
            // Горизонтальная прокрутка скроллом 
            function windowSize(){          
                var ScWidth = $(document).width();  // Узнаем ширину окна           
                if (ScWidth > '991'){
                    // Если ширна больше значения, выполняем горизонтальную прокрутку
                    $('html, body, *').mousewheel(function(e, delta) {
                        // Интенсивность скролла 80 
                        var isMac = /mac/i.test(navigator.platform);

                        if (isMac) {
                            this.scrollLeft -= (delta * 2);
                        } else {
                            this.scrollLeft -= (delta * 80);
                        }
                        e.preventDefault();
                    });

                    $(function() {
                    // Назначаем ширин блоку равную сумме блоков с классом calcme
                    overallwidth = 0;
                    $('.calcme').each(function() {
                        overallwidth = overallwidth + $(this).width() + parseInt($(this).css('padding-left')) + parseInt($(this).css('padding-right')) + parseInt($(this).css('margin-left')) + parseInt($(this).css('margin-right'));
                    });
                    $('.content').css('width', overallwidth);
                 });
                }
                    // Если ширина меньше, то ничего не делаем
            };
            
            // Выполняем при загрузке
            $(document).ready(function() {
                smWidth();
                windowSize();
            });
            // Выполняем при измении экрана
            $(window).resize(function() {
                smWidth();
                windowSize();
            });


The trick is that at a screen resolution of 991px, the horizontal scroll is canceled. Thus, when loading and resizing the window, the script calculates the width for the main container.
The trouble is that if you open the site in IE11, then the main container is not set to a fixed width, and if you resize the window and open it again, the script works.

What could be the problem?

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