position - Child image absolutely positioned, w/ dynamic dimensions. Need parent to have dynamic height to match the childs -
i understand can't done css, can done javascript?
i need image absolutely positioned because part of slideshow. when remove absolute positioning, each new image displays right of last image was. i've found code online says can div, haven't been able find applying javascript understand height of image.
css
.slideshowcontainer { border:5px solid #c7eafb; background:#ebebec; padding:0px; margin:0px; width:90%; clear:both; } #slideshow { position:relative; width:100%; height:300px; padding:none; margnin:none; } #slideshow img { position:absolute; top:0; left:0; z-index:8; width:100%; height:auto; padding:none; margin:none; } #slideshow img.active { z-index:10; } #slideshow img.last-active { z-index:9; }
html
<div class="slideshowcontainer"> <ul id="horizontal-style"> <li><a href=# >home</a></li> <li><a href=# >about us</a></li> <li><a href=# >online courses</a></li> <li><a href=# >registration</a></li> <li><a href=# >faculty</a></li> <li><a href=# >calendar</a></li> <li><a href=# >store</a></li> <li><a href=# >testimonials</a></li> <li><a href=# >online lectures</a></li> <li><a href=# >contact us</a></li> <li><a href=# >forum</a></li> </ul> <div id="slideshow"> <img src="images/dsc00537.jpg" class="active"/> <img src="images/dsc00407.jpg" /> <img src="images/dsc00566.jpg" /> <img src="images/jim_1871.jpg" /> </div><!-- end slideshow--> </div> <!-- end slideshowcontainer-->
jquery
$(function() { var $slideshow = $('#slideshow'), $slides = [], active = null; // build slides array children of slideshow. pull in children, adjust scope if needed $slideshow.children().each(function(i) { var $thisslide = $(this); // if active slide set index if ( $thisslide.hasclass('active') ) active = i; $slides.push( $thisslide ); }); // if no active slide, take last 1 if ( active === null ) active = $slides.length - 1; function slideswitch() { // add last-active class active slide var $lastactive = $slides[active]; $lastactive.addclass('last-active'); // find next slide active++; // set 0 if it's high if ( active >= $slides.length ) active = 0; var $nextactive = $slides[active]; $nextactive.css({opacity: 0.0}) .addclass('active') .animate({opacity: 1.0}, 1000, function() { $lastactive.removeclass('active last-active'); }); } // start interval setinterval( slideswitch, 5000 ); });
i figured out.
i added blank image of same proportions slideshow images after slide show , set z-index -1. allowed parent div fit around blank image , adjust accordingly around slide show.
html
<div class="slideshowcontainer"> <ul id="horizontal-style"> <li><a href=# >home</a></li> <li><a href=# >about us</a></li> <li><a href=# >online courses</a></li> <li><a href=# >registration</a></li> <li><a href=# >faculty</a></li> <li><a href=# >calendar</a></li> <li><a href=# >store</a></li> <li><a href=# >testimonials</a></li> <li><a href=# >online lectures</a></li> <li><a href=# >contact us</a></li> <li><a href=# >forum</a></li> </ul> <div id="slideshow"> <img src="images/dsc00537.jpg" class="active"/> <img src="images/dsc00407.jpg" /> <img src="images/dsc00566.jpg" /> <img src="images/jim_1871.jpg" /> </div><!-- end slideshow--> <!-- added code below solve issue --> <div class="test"> <img src="images/slideshowfiller.jpg" /> </div> </div> <!-- end slideshowcontainer-->
additional css
.test { margin:none; padding:none; z-index:-1; } .test img { width:100%; height:auto; }
Comments
Post a Comment