首页 > 代码库 > 【javascript】javascript实现background-size:cover的功能

【javascript】javascript实现background-size:cover的功能

    <script type=‘text/javascript‘>    $(function(){        var screenWidth = $(window).width();        var screenHeight = $(window).height();        //console.log(screenWidth+‘//‘+screenHeight);        var screenScale = screenWidth/screenHeight;        var imgWidth = $(‘.banner6 img‘).width();        var imgHeight = $(‘.banner6 img‘).height();        var scale = imgWidth/imgHeight;        if(screenScale > scale){            $(‘.banner6 img‘).width(screenWidth);//以宽为标准            $(‘.banner6 img‘).height(screenWidth/scale);            //console.log(‘11:‘+ $(‘.banner6 img‘).width()+‘:‘+$(‘.banner6 img‘).height());        }else{            $(‘.banner6 img‘).width(screenHeight*scale);//以高为标准            $(‘.banner6 img‘).height(screenHeight);            //console.log(‘22:‘+ $(‘.banner6 img‘).width()+‘:‘+$(‘.banner6 img‘).height());        }    })    </script>

【javascript】javascript实现background-size:cover的功能