html - vertical scrolling with fixed body -
here's deal. need lot of pictures in 1 line. many on whole width of site. need apply horizontal scrolling. problem header , footer. need fixed.
<div style="background-color: green; height: 80%"> <div style="background-color: purple; height: 100%; width: 1000px; white-space: nowrap"> <img style="max-height: 100%" src="barum/01.jpg"> <img style="max-height: 100%" src="barum/02.jpg"> <img style="max-height: 100%" src="barum/03.jpg"> <img style="max-height: 100%" src="barum/04.jpg"> <img style="max-height: 100%" src="barum/05.jpg"> <img style="max-height: 100%" src="barum/06.jpg"> <img style="max-height: 100%" src="barum/07.jpg"> </div> </div> <div style="background-color: red; height: 10%"></div>
thanks,
i'm assuming want have sticky/fixed header , footer, images appearing 100% vertically in-between.
nothing scales 100% height unless have each previous element (each successive parent) stretching 100% height html tag. or can use measurement vh
. example below not use vh
measurement.
here's jsfiddle of following: http://jsfiddle.net/fxxgb85f/6/
for following structure:
<body> <div class="header"></div> <div class="content"> <ul class="imglist"> <li><img src="http://sifatit.com/wp-content/uploads/2012/07/dummy-500x337.jpg" /></li> <li><img src="http://sifatit.com/wp-content/uploads/2012/07/dummy-500x337.jpg" /></li> <li><img src="http://sifatit.com/wp-content/uploads/2012/07/dummy-500x337.jpg" /></li> <li><img src="http://sifatit.com/wp-content/uploads/2012/07/dummy-500x337.jpg" /></li> <li><img src="http://sifatit.com/wp-content/uploads/2012/07/dummy-500x337.jpg" /></li> <li><img src="http://sifatit.com/wp-content/uploads/2012/07/dummy-500x337.jpg" /></li> <li><img src="http://sifatit.com/wp-content/uploads/2012/07/dummy-500x337.jpg" /></li> <li><img src="http://sifatit.com/wp-content/uploads/2012/07/dummy-500x337.jpg" /></li> <li><img src="http://sifatit.com/wp-content/uploads/2012/07/dummy-500x337.jpg" /></li> <li><img src="http://sifatit.com/wp-content/uploads/2012/07/dummy-500x337.jpg" /></li> <li><img src="http://sifatit.com/wp-content/uploads/2012/07/dummy-500x337.jpg" /></li> <li><img src="http://sifatit.com/wp-content/uploads/2012/07/dummy-500x337.jpg" /></li> <li><img src="http://sifatit.com/wp-content/uploads/2012/07/dummy-500x337.jpg" /></li> <li><img src="http://sifatit.com/wp-content/uploads/2012/07/dummy-500x337.jpg" /></li> <li><img src="http://sifatit.com/wp-content/uploads/2012/07/dummy-500x337.jpg" /></li> <li><img src="http://sifatit.com/wp-content/uploads/2012/07/dummy-500x337.jpg" /></li> <li><img src="http://sifatit.com/wp-content/uploads/2012/07/dummy-500x337.jpg" /></li> <li><img src="http://sifatit.com/wp-content/uploads/2012/07/dummy-500x337.jpg" /></li> <li><img src="http://sifatit.com/wp-content/uploads/2012/07/dummy-500x337.jpg" /></li> <li><img src="http://sifatit.com/wp-content/uploads/2012/07/dummy-500x337.jpg" /></li> <li><img src="http://sifatit.com/wp-content/uploads/2012/07/dummy-500x337.jpg" /></li> <li><img src="http://sifatit.com/wp-content/uploads/2012/07/dummy-500x337.jpg" /></li> <li><img src="http://sifatit.com/wp-content/uploads/2012/07/dummy-500x337.jpg" /></li> <li><img src="http://sifatit.com/wp-content/uploads/2012/07/dummy-500x337.jpg" /></li> <li><img src="http://sifatit.com/wp-content/uploads/2012/07/dummy-500x337.jpg" /></li> <li><img src="http://sifatit.com/wp-content/uploads/2012/07/dummy-500x337.jpg" /></li> <li><img src="http://sifatit.com/wp-content/uploads/2012/07/dummy-500x337.jpg" /></li> <li><img src="http://sifatit.com/wp-content/uploads/2012/07/dummy-500x337.jpg" /></li> </ul> </div> <div class="footer"></div> </body>
you have following css:
html, body { width: 100%; height: 100%; } body { margin: 0; padding: 50px 0; overflow: hidden; } *, *:before, *:after { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } .header { position: fixed; top: 0; left: 0; z-index: 5; width: 100%; height: 50px; background-color: #f00; } .footer { position: fixed; bottom: 0; left: 0; z-index: 5; width: 100%; height: 50px; background-color: #f00 } .content { position: relative; margin: 0; display: block; width: 100%; height: 100%; max-height: 100%; overflow-x: auto; } ul.imglist { position: absolute; top: 0; left: 0; margin: 0; padding: 0; width: 100%; height: 100%; list-style-type: none; overflow-x: auto; overflow-y: hidden; } ul.imglist li { margin: 0 5px 0 0; padding: 0; display: block; float: left; width: 100%; height: 100%; } ul.imglist li img { display: block; width: auto; height: 100%; }
jquery:
$(document).ready(function(){ horscoll(); // on load , on resize $(window).on('load resize', function(){ horscoll(); }); }); function horscoll(){ var parentsel = $('ul.imglist'); var listsel = $('ul.imglist li'); var licount = $('ul.imglist li').length; var imgwidth = $('ul.imglist li img').width(); parentsel.css({ width: licount * imgwidth }); listsel.css({ maxwidth: imgwidth }); }
Comments
Post a Comment