SliderCarousel

  • user warning: Got error 28 from storage engine query: SELECT node.nid AS nid, node_revisions.body AS node_revisions_body, node_revisions.format AS node_revisions_format, node.title AS node_title, RAND() AS _random FROM node node LEFT JOIN node_revisions node_revisions ON node.vid = node_revisions.vid WHERE (node.type in ('quote')) AND (node.status <> 0 OR (node.uid = 0 AND 0 <> 0) OR 0 = 1) ORDER BY _random ASC LIMIT 0, 1 in /var/www/jg-soft.com/modules/acquia/views/includes/view.inc on line 755.
  • user warning: Got error 28 from storage engine query: SELECT node.nid AS nid, node_data_field_images.field_images_fid AS node_data_field_images_field_images_fid, node_data_field_images.field_images_list AS node_data_field_images_field_images_list, node_data_field_images.field_images_data AS node_data_field_images_field_images_data, node_data_field_images.delta AS node_data_field_images_delta, node.type AS node_type, node.vid AS node_vid, RAND() AS _random FROM node node LEFT JOIN content_field_images node_data_field_images ON node.vid = node_data_field_images.vid INNER JOIN term_node term_node ON node.vid = term_node.vid LEFT JOIN term_node term_node2 ON node.vid = term_node2.vid AND term_node2.tid = 41 WHERE (node.status <> 0 OR (node.uid = 0 AND 0 <> 0) OR 0 = 1) AND (node.type not in ('project')) AND (node_data_field_images.field_images_list <> 0) AND (term_node.tid = 13) AND (term_node2.tid IS NULL) ORDER BY _random ASC LIMIT 0, 1 in /var/www/jg-soft.com/modules/acquia/views/includes/view.inc on line 755.
AttachmentSize
SliderCarousel.js2.6 KB

This is an object that makes use of jquery to create a carousel with a nice sliding effect between slide transitions. I've included examples of the html it needs to work and the initialization of it.

Using jquery, after the page loads, jquery kicks in and attaches the carousel to the html. The SliderCarousel constructor requires 2 parameters: 1) the class of the container element to attach to, 2) The number of miliseconds between slide transitions.

When styled all proper like, the image elements will slide either up or down (scroll actually), depending on which item is next in the rotation. If a user clicks on one of the control anchors, the slider will transition to the image belonging to the control which they clicked on.

 

CSS

  1. .slider-carousel {
  2. position:relative;
  3. height:400px;
  4. }
  5. .slider-carousel .controls{
  6. position:relative;
  7. top:55px;
  8. }
  9. .slider-carousel .controls .summary,
  10. .slider-carousel .active-control .tab{
  11. display:none;
  12. }
  13. .slider-carousel .active-control .summary{
  14. display:block;
  15. }
  16.  
  17. .slider-carousel .images{
  18. position:absolute;
  19. top:55px;
  20. right:0;
  21. width:600px;
  22. height:340px;
  23. overflow:hidden;
  24. }

HTML

  1. <div class="slider-carousel">
  2. <div class="controls">
  3. <div id="control-0" class="control active-control">
  4. <div class="tab"><a href="javascript:void(0)"><span>Promo 2</span></a></div>
  5.  
  6. <div class="summary">
  7. <h3 class="title">Promo 2</h3>
  8. <div class="hero-footer"></div>
  9. </div>
  10. </div>
  11. <div id="control-1" class="control">
  12. <div class="tab"><a href="javascript:void(0)"><span>Promo 5</span></a></div>
  13.  
  14. <div class="summary">
  15. <h3 class="title">Promo 5</h3>
  16. <div class="hero-footer"></div>
  17. </div>
  18. </div>
  19. <div id="control-2" class="control">
  20. <div class="tab"><a href="javascript:void(0)"><span>Promo 1</span></a></div>
  21.  
  22. <div class="summary">
  23. <h3 class="title">Promo 1</h3>
  24. <div class="hero-footer"></div>
  25. </div>
  26. </div>
  27. </div>
  28.  
  29. <div class="images">
  30. <div id="image-0" class="image active-image">
  31. <img src="http://localhost:8100/sites/default/files/imagecache/600x340/hero_promo/3d-landscapes-terragen01.jpg"
  32. alt="" title="" width="600" height="340" />
  33. </div>
  34. <div id="image-1" class="image">
  35. <img src="http://localhost:8100/sites/default/files/imagecache/600x340/hero_promo/68landscapes04-m241.jpg"
  36. alt="" title="" width="600" height="340" />
  37. </div>
  38. <div id="image-2" class="image">
  39. <img src="http://localhost:8100/sites/default/files/imagecache/600x340/hero_promo/2PacGreatestHits.jpg"
  40. alt="" title="" width="600" height="340" />
  41. </div>
  42. </div>
  43. </div>

Javascript Initialization

  1. $(document).ready(function(){
  2. carousel = new ScrollerCarousel('.slider-carousel', 12000);
  3. });

Javascript

  1. /**
  2.  * Name: SliderCarousel
  3.  * Author: Jason Gordon
  4.  * Description: Implements a dynamic carousel where the slides scroll instead of
  5.  * fade in and fade out.
  6.  */
  7. ScrollerCarousel = function(container, rotationInterval) {
  8.  
  9. var self = this; // We need selc because the scope/value of 'this' can change.
  10. //this.rotationInterval = rotationInterval;
  11. this.rotationInterval = 3000;
  12. this.container = $(container);
  13. this.interval = null;
  14.  
  15.  
  16. this.rotate = function(target){
  17. var activeId = this.getActiveId();
  18.  
  19. // If no target is defined, rotate to the next slide.
  20. if( target == undefined ){
  21. target = activeId + 1;
  22.  
  23. if( target >= this.container.find('.image').length ) {
  24. target = 0;
  25. }
  26. }
  27.  
  28. this.updateControls(target);
  29.  
  30. // Scroll the image to the target spot
  31. var scrollTop = target * this.container.find('.images').height();
  32. this.container.find('.images').animate({'scrollTop': scrollTop}, 'normal');
  33. }
  34.  
  35. this.attachControls = function(){
  36. this.container.find('.control .tab a').click(function(){
  37. id = $(this).parent().parent().attr('id').replace('control-', '');
  38. self.rotate(id);
  39. }).hover(function(){
  40. self.pause();
  41. }, function(){
  42. self.resume();
  43. });
  44.  
  45. this.container.find('.control .summary').hover(function(){
  46. self.pause();
  47. }, function(){
  48. self.resume();
  49. });
  50. }
  51.  
  52. this.updateControls = function(target){
  53. var activeControl = this.container.find('.active-control');
  54. var targetControl = this.container.find('#control-' + target);
  55.  
  56. // Slide up active control summary and slide down active control tab
  57. activeControl.find('.summary').slideUp('slow');
  58.  
  59. // Slide down the active tab so it is now revealed
  60. activeControl.find('.tab').slideDown('slow');
  61.  
  62. // Slide up target control tab and slide down the target control summary
  63. targetControl.find('.tab').slideUp('slow');
  64. targetControl.find('.summary').slideDown('slow', function(){
  65. activeControl.removeClass('active-control');
  66. targetControl.addClass('active-control');
  67. });
  68. }
  69.  
  70. this.pause = function (){
  71. window.clearInterval(this.interval);
  72. }
  73.  
  74. this.resume = function (){
  75. this.interval = window.setInterval('carousel.rotate()', this.rotationInterval);
  76. }
  77.  
  78. this.getActiveId = function(){
  79. if( this.container.find('.active-control').attr('id') == undefined ){
  80. return 0;
  81. }
  82.  
  83. return parseInt(this.container.find('.active-control').attr('id').replace('control-', ''));
  84. }
  85.  
  86. this.attachControls();
  87. this.resume();
  88. }