【问题标题】:Resize slider with javascript使用 javascript 调整滑块大小
【发布时间】:2018-01-05 03:27:04
【问题描述】:

当前代码:

cover_height: function() {

        if (!$('.typology-cover-empty').length) {

            var cover_height = $(window).height() - this.settings.admin_bar_height + Math.abs(parseInt($('.typology-section:first').css('top'), 10));
            var cover_content_height = $('.cover-item-container').height();
            var header_height = $('#typology-header').height();
            var cover_auto = true;

            if (cover_height < 450) {
                cover_height = 450;
            }

            if (cover_content_height > cover_height - header_height) {
                cover_height = cover_content_height + header_height + 100;
                cover_auto = false;
            }


            if ($(window).width() <= 1366) {

                this.settings.cover_height = cover_height;
                $('.typology-cover-item').css('height', cover_height);
                $('.typology-cover').css('height', cover_height);

            } else {
                $('.typology-cover-item').css('height', $('.typology-cover').height());
                $('.typology-cover').css('height', $('.typology-cover').height());
                this.settings.cover_height = $('.typology-cover').height();
            }

            if (cover_auto) {
                if (!$('.typology-cover-slider').length) {
                    $('.typology-cover-item').css('position', 'fixed');
                } else {
                    $('.typology-slider-wrapper-fixed').css('position', 'fixed');
                }
            }

        }
    },

为了降低滑块的高度,我必须进行哪些更改? 如果你去网站你会看到它真的很大。 该网站是审查,基本上这会根据上面的代码调整大小。但我想让它更小。

【问题讨论】:

  • 您是否只对通过 Javascript 或 CSS 降低高度感兴趣?
  • 如果可能的话,我想通过更改上面代码中的一些内容来通过 Javascript 调整它的大小。如果没有,那么我只需删除 javascript 代码并自己做 CSS。

标签: javascript header height


【解决方案1】:

滑块高度由该脚本计算。计算取决于窗口高度和滑块内容的高度。我认为设置滑块的固定高度不是一个好主意。如果这样做,您将失去滑块响应能力。

这里是滑块高度设置:

    if ($(window).width() <= 1366) {

        this.settings.cover_height = cover_height;// this variable contains the calculated height if the windows width is lower than 1366
        $('.typology-cover-item').css('height', cover_height);// Here the sliders Elements are set to the calculated height if the windows width is lower than 1366
        $('.typology-cover').css('height', cover_height);// Here the sliders Elements are set to the calculated height if the windows width is lower than 1366

    } else {
        $('.typology-cover-item').css('height', $('.typology-cover').height());// if windows width is greater than 1366 sliders Elements are set to its "natural height"
        $('.typology-cover').css('height', $('.typology-cover').height());
        this.settings.cover_height = $('.typology-cover').height();// if windows width is greater than 1366 sliders Elements are set to its "natural height"
    }

你可以这样做来降低高度:

    var reduceHeightValue = 50;
    if ($(window).width() <= 1366) {

        this.settings.cover_height = cover_height - reduceHeightValue;// reduce the height by 50 if windows width is lower than 1366
        $('.typology-cover-item').css('height', cover_height);// Here the sliders Elements are set to the calculated height if the windows width is lower than 1366
        $('.typology-cover').css('height', cover_height);// Here the sliders Elements are set to the calculated height if the windows width is lower than 1366

    } else {
        $('.typology-cover-item').css('height', $('.typology-cover').height() - reduceHeightValue);// reduce the height by 50 if windows width is greater than 1366
        $('.typology-cover').css('height', $('.typology-cover').height() - reduceHeightValue);// reduce the height by 50 if windows width is greater than 1366
        this.settings.cover_height = $('.typology-cover').height() - reduceHeightValue;// reduce the height by 50 if windows width is greater than 1366
    }

这种技巧可以为您工作,但大多数时候以这种方式更改现有代码并不是一个好主意,因为它会破坏某些东西。 显然,此滑块有一些设置可以设置高度。我建议使用此设置。阅读滑块的文档并以适当的方式设置高度。

【讨论】:

    【解决方案2】:

    试试这个:

    cover_height: function() {
    
        if (!$('.typology-cover-empty').length) {
    
            var cover_height = $(window).height() - this.settings.admin_bar_height + Math.abs(parseInt($('.typology-section:first').css('top'), 10));
            var cover_content_height = $('.cover-item-container').height();
    
            $('#typology-header').height(150);// Set the height in pixel
            var header_height = $('#typology-header').height();
            var cover_auto = true;
    
            if (cover_height < 450) {
                cover_height = 450;
            }
    
            if (cover_content_height > cover_height - header_height) {
                cover_height = cover_content_height + header_height + 100;
                cover_auto = false;
            }
    
    
            if ($(window).width() <= 1366) {
    
                this.settings.cover_height = cover_height;
                $('.typology-cover-item').css('height', cover_height);
                $('.typology-cover').css('height', cover_height);
    
            } else {
                $('.typology-cover-item').css('height', $('.typology-cover').height());
                $('.typology-cover').css('height', $('.typology-cover').height());
                this.settings.cover_height = $('.typology-cover').height();
            }
    
            if (cover_auto) {
                if (!$('.typology-cover-slider').length) {
                    $('.typology-cover-item').css('position', 'fixed');
                } else {
                    $('.typology-slider-wrapper-fixed').css('position', 'fixed');
                }
            }
    
        }
    },
    

    【讨论】:

    • 是的,这会增加标题的大小,但滑块仍然很大。那是我的问题,也许我没有解释清楚。
    • so 将值更改为适合您需要的高度 $('#typology-header').height(150);// 以像素为单位设置高度
    • 是的,我理解那部分,但这会改变标题。我需要修复此标题下方的滑块。增加标题会使它的滑块看起来更小,但并不那么明显。
    • 这里还有一些滑块代码,也许这里可以更改?pastebin.com/AAKG8V2x
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-16
    • 2013-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多