octocatstartv

vDboy

A Pen By Rob G

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource
via CSS Lint

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource
via JS Hint

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Want a Run Button?

If active, the preview will update automatically when you change code.

HTML

            
              <a href="http://css-tricks.com/revealing-photo-slider/">CSS-Tricks Photo Slider</a> to answer <a href="http://css-tricks.com/forums/discussion/24337/javascript-help-please-with-revealing-photo-slider-with-jquery-by-css-tricks">this question</a>

<table>
  <tr>
		<td>
      <div class="photo_slider">
			  <img src="http://placekitten.com/500/333"/>
			  <div class="info_area">
			  	<h3>Kitties</h3>
			  	<p><em>By: <a href="#">Kitties!</a></em></p>
			  </div>
		  </div>
    </td>
    <td>
      <div class="photo_slider">
      	<img src="http://placehold.it/500x333"/>
       	<div class="info_area">
       		<h3>Plain Grey</h3>
       		<p><em>By: <a href="#">Plain Grey</a></em></p>
       	</div>
      </div>
    </td>
		<td>
      <div class="photo_slider">
			  <img src="http://placebear.com/500/333"/>
			  <div class="info_area">
				  <h3>Da Bears</h3>
				  <p><em>By: <a href="#">Da Bears</a></em></p>
			  </div>
		  </div>
    </td>
		<td>
      <div class="photo_slider">
			  <img src="http://lorempixel.com/500/333"/>
			  <div class="info_area">
				  <h3>Random</h3>
				  <p><em>By: <a href="#">Random</a></em></p>
			  </div>
		  </div>
    </td>
	</tr>
</table>

            
          
!

CSS

            
              a.close {
	position: absolute;
	right: 10px;
	bottom: 10px;
	display: block;
	height: 21px;
  cursor: pointer;
}

.photo_slider_img {
	width: 100px;
	height: 100px;
	margin-bottom: 5px;
	overflow: hidden;
}

td {
	vertical-align: top;
}

.photo_slider {
	position: relative;
	width: 100px;
	height: 130px;
	padding: 10px;
	border: 1px solid black;
	overflow: hidden;
	margin: 25px 10px 10px 10px;
	background: white;
	float: left;
}

.info_area {
	display:none;
}

.more_info {
	display: block;
	width: 89px;
	height: 26px;
	cursor: pointer;
}
            
          
!

JS

            
              // Window load event, slower than DOM Ready but needed because of image calculations
$(window).bind("load", function() {  
			
	$('.photo_slider').each(function(){
		
		var $this = $(this).addClass('photo-area');
		var $img = $this.find('img');
		var $info = $this.find('.info_area');
			
		var opts = {};
		
		opts.imgw = $img.width();
		opts.imgh = $img.height();
		
		opts.orgw = $this.width();
		opts.orgh =  $this.height();
		
		$img.css ({
			marginLeft: "-150px",
			marginTop: "-150px"
		});
		
		var $wrap = $('<div class="photo_slider_img">').append($img).prependTo($this);
	
		var $open = $('<a href="#" class="more_info">More Info &gt;</a>').appendTo($this);
		
		var $close = $('<a class="close">Close</a>').appendTo($info);
		
		opts.wrapw = $wrap.width();
		opts.wraph = $wrap.height();
		
		$open.click(function(){
			$this.animate({ 
				width: opts.imgw,
				height: (opts.imgh+95),
				borderWidth: "10"
				
			}, 600 );
					
			$open.fadeOut();
			
			$wrap.animate({ 
			    width: opts.imgw,
				height: opts.imgh
			}, 600 );
	
			$(".info_area",$this).fadeIn();
			
			$img.animate({
				marginTop: "0px",
				marginLeft: "0px"
			}, 600 );
			
      $this.closest('td')
        .siblings().find('.close').click();
      
			return false;
		});
		
		$close.click(function(){
			$this.animate({ 
				width: opts.orgw,
				height: opts.orgh,
		        borderWidth: "1"
		      }, 600 );
			
			$open.fadeIn();
			
			$wrap.animate({ 
		        width: opts.wrapw,
				height: opts.wraph
			      }, 600 );
			
				$img.animate({
					marginTop: "-150px",
					marginLeft: "-150px"
				}, 600 );
	
			$(".info_area",$this).fadeOut();
			return false;
		});
		
	});

});
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console