Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
  article, aside, figure, footer, header, hgroup, 
  menu, nav, section { display: block; }
  div.slide { padding:20px; color: #fff; background: red; width:400px; height:400px; }
  #status { float:right; width: 100px; background:#444; color:#fff; padding:10px; border:1px solid #999;}
</style>
</head>
<body>
  <div id="status"></div>
  <div class="slide">
    <h1>Slide One</h1>
  </div>
  <div class="slide">
    <h1>Slide Two</h1>
  </div>
  <div class="slide">
    <h1>Slide Three</h1>
  </div>
  <div class="slide">
    <h1>Slide Four</h1>
  </div>
</body>
</html>
 
//wrap the whole plugin in a closure
(function($){
  
  //create a jQuery collection method
  $.fn.clickthrough = function(options){
    
    //private vars
    var number_of_slides = this.length,
        slides = this,
        settings = $.extend({
          'bg_color' : 'red',
          'text_color' : 'white'
        }, options); // we have set some defaults and merged them with the incoming 'options' object
    
    return this.each(function(i, slide){
      
      var next_slide = (i + 1 < number_of_slides) ? i + 1 : 0;
      
      if(i > 0)
          $(slide).hide();
      
      $(slide).bind('click', function(){
        
        $(this).fadeOut('slow', function(){
          
          $(slides.eq(next_slide))
            .show()
            .trigger('slideOpen', (next_slide + 1)); //custom event trigger which passes the opened slide index + 1 to offset zero indexing
          
        });
        
      })
        .css('background', settings.bg_color)
        .css('color', settings.text_color);
      
    });
    
  };
  
})(jQuery);
$(document).ready(function(){
  
  $('div.slide').clickthrough({
    'bg_color' : 'blue',
    'text_color' : 'yellow'
  }).bind('slideOpen', function(event, slide_id){
    $('#status').html('slide ' + slide_id + ' open');
  });
  
});
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers