javascript - 在响应式 slider 中设置高度(jQuery Cycle)

标签 javascript jquery html css cycle

我正在使用 jQuery Cycle 制作几张幻灯片,下面是内容。 jQuery Cycle 将parent设置为relative,child滑动设置为absolute,这样应该在它下面的内容就被覆盖了。通常,我会给父容器一个高度来解决我的问题。

由于布局是响应式的,所以高度可以改变。有没有简单的解决方案?

编辑:

这是为我做的事情:

$(window).load(function(){

    var rotate_height = $('#rotate div img').height();
    $('#rotate').css('height', rotate_height);

    $(window).resize(function() {
        if($(window).width() >= 960){
            rotate_height = 290;
            $('#rotate').css('height', rotate_height);
            $('#rotate').cycle('next');
        } else if ($(window).width() >= 768 && $(window).width() <= 959) {
            rotate_height = 230;
            $('#rotate').css('height', rotate_height);
            $('#rotate').cycle('next');
        } else if ($(window).width() >= 480 && $(window).width() <= 767) {
            rotate_height = 210;
            $('#rotate').css('height', rotate_height);
            $('#rotate').cycle('next');
        } else if ($(window).width() <= 479) {
            rotate_height = 150;
            $('#rotate').css('height', rotate_height);
            $('#rotate').cycle('next');
        }
    });

    $('#rotate').cycle({
        fx: 'fade',
        fit: 1,
        containerResize: 0,
        slideResize: 0,
        height: rotate_height       
    });
});

cycle('next') 会在访问者调整显示器大小后强制将幻灯片切换到下一张。不理想,但图像不会按比例缩小,只有在更换幻灯片之后。

最佳答案

这是我的解决方案:

$(window).resize(function(){
    $('.cycle-container').each(function(){      
        $(this).height($(this).find('> *:first').outerHeight());
    })
});

关于javascript - 在响应式 slider 中设置高度(jQuery Cycle),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9460030/

相关文章:

javascript - 隐藏元素并根据下拉选择不需要它们

javascript - 无法部署待办事项;无法删除容器 (todos-frontend)

jquery - 从字符串数组中删除空字符串 - JQuery

javascript - 对象中的分隔符

php - 选择与下拉列表中显示的值不同的值。 (PHP 和 MySQL)

Javascript call() 函数 - 额外参数

javascript - Shortid的唯一性如何保证?

javascript - 如何使用 jQuery 禁用多个链接?

html - 如何将自定义内容添加到新的 Google 协作平台

javascript - 按下按钮时动态创建的 iframe 在所有浏览器上立即消失