Supersized - How to stretch images?

2019-08-12 16:26发布

问题:

I'm trying to get supersized not to crop images and stretch them to fill the background 100% in width and height (I don't care if the images get distorted).

I'm using fit_always so the images don't get cropped and in the CSS:

#supersized img { 
    width:100%;
    height:100%;
    position:relative;
    display:none;
    outline:none;
    border:none;
 }

HTML

<script type="text/javascript">  
jQuery(function($){  
  $.supersized({  
    // Functionality
    slide_interval : 5000,
    transition : 1,
    transition_speed : 500,
    horizontal_center : 0,
    fit_always : 1,

    // Components                           
    slides : [ // Slideshow Images
              {image : '/img/main/home.jpg'},
              {image : '/img/main/home-2.jpg'},
              {image : '/img/main/home-3.jpg'},
              {image : '/img/main/home-4-test.jpg'},
              {image : '/img/main/home-4.jpg'}
             ]    
  });
});
</script>

Works fine, but if I resize the browser window the width:100% and height:100% gets "forgotten"

What am I missing?

回答1:

Have you tried "auto" instead of 100% ?

#supersized img { 
   width:auto;
   height:auto;
   position:relative;
   display:none;
   outline:none;
   border:none;
 }


回答2:

In my experience, the default settings for Supersized do just what you want, without anything like fit_always. In the demo code I have saved locally, the JS is like this:

$(function(){
    $.fn.supersized.options = {  
        startwidth: 640,  
        startheight: 480,
        vertical_center: 1,
        slideshow: 1,
        navigation: 1,
        thumbnail_navigation: 1,
        transition: 1, //0-None, 1-Fade, 2-slide top, 3-slide right, 4-slide bottom, 5-slide left
        pause_hover: 0,
        slide_counter: 1,
        slide_captions: 1,
        slide_interval: 3000,
        slides : [
            {image : 'slides/tower.jpg', title : 'City Clock Tower', url : 'http://www.flickr.com/photos/wumbus/4582735030/in/set-72157623876357531/'},
            {image : 'slides/fence.jpg', title : 'Canal Park Fence', url : 'http://www.flickr.com/photos/wumbus/4582735030/sizes/l/in/set-72157623876357531/'},  
            {image : 'slides/tracks.jpg', title : 'Old Train Tracks', url : 'http://www.flickr.com/photos/wumbus/4582733542/in/set-72157623876357531/'}
        ]
    };
    $('#supersized').supersized(); 
});


回答3:

This problem can be happen for container width/height. You already set image width height to 100%. It will work. If your container isn't 100% in width/height then image can't be. If there is no container then use 100% for body,html.



回答4:

Try this

 #supersized img {                      
    background-repeat:no-repeat;
    background-size:100% 100%;
    }