如何将动态创建的自举旋转木马映像的大小设置为桌面尺寸,无论上载图像大小如何



我已经尝试过这样的东西,但是它并不适当地拟合到窗口的屏幕上。有一个空间可以上下滚动,但是如果它适当地适合屏幕。

$(document).ready(function () {
        var $item = $('.carousel .item');
        var $Wwidth = $(window).width();
        $item.eq(0).addClass('active');
        $item.width($Wwidth);
        $item.addClass('full-screen');
        $(window).on('resize', function () {
            $item.width($Wwidth);
        });                    
 }

最后,我通过声明一个高度变量来解决此问题,如下所示。如果有人面临同样的问题,这将对他们有所帮助。

        $(document).ready(function () {
        var $item = $('.carousel .item');
        var $Wwidth = $(window).width();
        var $wHeight = $(window).height();
        $item.eq(0).addClass('active');
        $item.height($wHeight);
        $item.width($Wwidth);
        $item.addClass('full-screen');
        $(window).on('resize', function () {
            $item.height($wHeight);
            $item.width($Wwidth);
        });
    });

最新更新