Код:
<style>#slideshow { margin:0 auto; width:370px; height: 100px; position:relative; line-height: 10px; } #slideshow #slidesContainer { margin:0 auto; width:300px; height: 100px; overflow:auto; /* allow scrollbar */ position:relative; } #slideshow #slidesContainer .slide { margin:0 auto; width:300px; /* reduce by 20 pixels of #slidesContainer to avoid horizontal scroll */ height:100px; } /** * Slideshow controls style rules. */ .control { display:block; width: 100px; height: 163px; text-indent:-10000px; position:absolute; cursor: pointer; } #leftControl { top: 45px; left: 20px; background:transparent url(http://10pix.ru/img1/242918/5352879.png) no-repeat 0 0; } #rightControl { top: 45px; right: -70px; background:transparent url(http://10pix.ru/img1/1215/5352880.png) no-repeat 0 0; } /*Style rules for Demo page */ * { margin:0; padding:0; } .slide h2, .slide p { margin:15px; } .slide h2 { letter-spacing:-1px; } .slide img { float:right; margin:0 15px; } </style> <script type="text/javascript"> $(document).ready(function(){ var currentPosition = 0; var slideWidth = 300; var slides = $('.slide'); var numberOfSlides = slides.length; // Remove scrollbar in JS $('#slidesContainer').css('overflow', 'hidden'); // Wrap all .slides with #slideInner div slides .wrapAll('<div id="slideInner"></div>') // Float left to display horizontally, readjust .slides width .css({ 'float' : 'right', 'width' : slideWidth }); // Set #slideInner width equal to total width of all slides $('#slideInner').css('width', slideWidth * numberOfSlides); // Insert controls in the DOM $('#slideshow') .prepend('<span class="control" id="leftControl">Clicking moves left</span>') .append('<span class="control" id="rightControl">Clicking moves right</span>'); // Hide left arrow control on first load manageControls(currentPosition); // Create event listeners for .controls clicks $('.control') .bind('click', function(){ // Determine new position currentPosition = ($(this).attr('id')=='rightControl') ? currentPosition+1 : currentPosition-1; // Hide / show controls manageControls(currentPosition); // Move slideInner using margin-left $('#slideInner').animate({ 'marginLeft' : slideWidth*(-currentPosition) }); }); // manageControls: Hides and Shows controls depending on currentPosition function manageControls(position){ // Hide left arrow if position is first slide if(position==0){ $('#leftControl').hide() } else{ $('#leftControl').show() } // Hide right arrow if position is last slide if(position==numberOfSlides-1){ $('#rightControl').hide() } else{ $('#rightControl').show() } } }); </script> <div style="width: 300px; height:100px; text-align: justify; border: none; font-family: arial; font-size: 11px; line-height: 2px; margin: 1px; position: absolute; margin-left: 50px; top: 40px; "> <div id="pageContainer"> <!-- Slideshow HTML --> <div id="slideshow"> <div id="slidesContainer"> <div class="slide"> <p> Третий контейнер </p> </div> <div class="slide"> <p> Второй контейнер </p> </div> <div class="slide"> <p> Первый контейнер </p> </div> </div> </div> <!-- Slideshow HTML --> </div></div>