cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

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

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div style="overflow:hidden; padding:70px 0 30px;">
  <div class="row">
    <div class="col lrg-12">

        <div class="slider-wrap">
          <div class="slider">
            <div class="outer">
              <div class="tray">
                <section id="all-articles" style="left:-100%;"><img src="http://placehold.it/650x500/2ecc71/ffffff"></section>
                <section id="featured-articles" style="left:0%;" class="current"><img src="http://placehold.it/650x500/e74c3c/ffffff"></section>
                <section id="popular-articles" style="left:100%;"><img src="http://placehold.it/650x500/3498db/ffffff"></section>
                <section id="new-articles" style="left:200%;"><img src="http://placehold.it/650x500/f39c12/ffffff"></section>
              </div>
            </div>
            <div class="mask left">
              <a href="#" class="arrow left"><span>All</span></a>
            </div>
            <div class="mask right">
              <a href="#" class="arrow right"><span>Popular</span></a>
            </div>
          </div>
          <nav class="slider-nav">
            <ul>
              <li class="current"><a href="#featured-articles">Featured</a></li>
              <li><a href="#popular-articles">Popular</a></li>
              <li><a href="#new-articles">New</a></li>
              <li><a href="#all-articles">All</a></li>
            </ul>
            <span class="highlight"></span>
          </nav>
        </div>

      </div>
  </div>
</div>
          
            
          
!
            
              @import "compass/css3";

$blue: #0380a5;
$grey: #dfdfde;

//grid
$max-width: 650px;
$col-gutter: 30px;
$break-large: 400px;

.clearfix { display:table; line-height:0; content:""; clear:both; }
.row {
    max-width:$max-width + $col-gutter; margin:0 auto;
    .row { margin-left:-$col-gutter; margin-right:-$col-gutter; }
    .col { @include box-sizing(border-box); padding-left:$col-gutter; padding-right:$col-gutter; }
    &:after { @extend .clearfix; }
}

//large grid classes
@media (min-width:$break-large) {
    .hide-lrg { display:none; }
    @for $i from 1 through 12 {
      .lrg-#{$i} { width:$i/12*100%; float:left; }
    }
}

//bbc slider
.slider-wrap {
	.slider { height:250px; position:relative; }
	.outer { position:relative; }
	.outer, .tray, section { height:100%; }
	.tray, section { position:absolute; width:100%; height:100%; }
	section { 
	  background:rgba(#000,0.2); overflow:hidden;
    img { width:100%; max-width:100%; }
	}
	.arrow {
		position:absolute; top:50%; margin-top:-30px; height:60px; width:60px; z-index:1; cursor:pointer; z-index:15; background-color:black; 
		&.left {
      right:-30px; background-image:url(https://www.garethweaver.com/codepen/images/bbc-left.png);
      span { left:60px; padding:0 20px 0 0; }
    }
		&.right {
      left:-30px; background-image:url(https://www.garethweaver.com/codepen/images/bbc-right.png);
      span { right:60px; padding:0 0 0 20px;  }
    }
    span { height:60px; line-height:60px; background:$blue; position:absolute; display:none; color:#fff;}
    &:hover {
      background-color:$blue;
      span { display:block; }
    }
	}
	.mask {
		display:block; position:absolute; top:0; height:100%; width:200%; background:rgba(#fff,0.7); z-index:10; cursor:pointer;
		&.left { right:100%; }
		&.right { left:100%; }
	}
	.slider-nav { 
		position:relative; font-size:14px; text-align:center; margin:15px 0 0; overflow:hidden;
		ul { position:relative; margin:0; padding:0; }
		li {
			float:left; width:25%; box-sizing:border-box;
			&.current a { color:$blue; }
      
      a {
        @include transition(color 0.2s ease-in-out); height:60px; line-height:60px; border-top:4px solid $grey; display:block; font-weight:bold; margin:0 4px;
        &:hover { color:$blue; }
       }
      
		}
		.highlight { position:absolute; margin:0 4px; top:0; left:0; width:24%; box-sizing:border-box; border-top:4px solid $blue; }
	}
	
}
            
          
!
            
              //BBC hompage slider
var homeSlider = {

	vars: {
		//tray position
		pos: 0,
		//lock the slider to prevent multiple clicks when animating
		locked: 0,
     //animation duration
     duration: 1000
	},

	helpers: {

		//return percent from .att('style')
		getPercent: function(str){
			var foo = str.substring(str.indexOf('left:')+5);
			return parseInt(foo.substring(0, foo.indexOf('%')));
		},

		//unlock the slider post animation
		unlock: function(){
			homeSlider.vars.locked = 0;
		}

	},

	//bind all the things
	init: function(){

		//click binds
		$('.slider .mask').on('mouseenter mouseleave', homeSlider.peek.over);
		$('.slider .mask').on('click', homeSlider.nav.arrow);
		$('.slider-nav a').on('click', homeSlider.nav.menu);

		//mobile support
		/*
		$('.slider .outer').swipe({
			swipe: function(event, direction, distance, duration, fingerCount){
				if ( direction === 'left' ){
					$('.mask.right').click();
				} else if ( direction === 'right' ){
					$('.mask.left').click();
				}
			},
			threshold: 40
		});
		*/
	},

	peek: {

		//hover on masks triggers peek direction
		over: function(e){
			if (e.type == 'mouseenter' && $(this).hasClass('left')) {
				homeSlider.peek.move(15);
			} else if (e.type == 'mouseenter' && $(this).hasClass('right')) {
				homeSlider.peek.move(-15);
			} else {
				homeSlider.peek.move(0);
			}
		},

		//peek move
		move: function(dist){
			$('.slider-wrap .outer').stop().animate({'left': dist}, 300);
		}

	},

	nav: {

		//handles arror nav click
		arrow: function(e){
			e.preventDefault();
			if ( homeSlider.vars.locked === 0) {
				homeSlider.vars.locked = 1;
				if ( $(this).hasClass('left') ){
					homeSlider.move.direction(0);
				} else {
					homeSlider.move.direction(1);
				}
			}
		},

		//handles a menu nav click
		menu: function(e){
			e.preventDefault();
			if ( homeSlider.vars.locked === 0) {
				homeSlider.vars.locked = 1;
				homeSlider.move.toSlide($(e.target.hash));
			}
		},

		//updates the menu nav visual class and arrow text
		update: function(){
       //nav menu
			homeSlider.move.currentClass($('.slider-nav').find('a[href="#' + $('.slider .current').attr('id') + '"]').parent());
			var offset = $('.slider-nav li.current').position().left / $('.slider-nav').width() * 100;
			$('.slider-nav .highlight').stop().animate({'left': offset+'%'}, homeSlider.vars.duration, 'easeInOutQuart');
       //update arrow text
       $('.arrow.right span').text($('.slider-nav').find('a[href="#' + $('.slider .current').next().attr('id') + '"]').text());
       $('.arrow.left span').text($('.slider-nav').find('a[href="#' + $('.slider .current').prev().attr('id') + '"]').text());
		}

	},

	move: {

		direction: function(dir){

			var $curr = $('.slider .current');

			//go right
			if (dir === 1) {
				homeSlider.vars.pos -= 100;
				if ( $curr.next().is(':last-child') ){
					//append first to last
					homeSlider.move.firstToLast();
					homeSlider.move.animate(homeSlider.vars.pos, true);
				} else {
					//no appendingzings
					homeSlider.move.animate(homeSlider.vars.pos, false);
				}
				homeSlider.move.currentClass($curr.next());

			//go left
			} else {
				homeSlider.vars.pos += 100;
				if ( $curr.prev().is(':first-child') ){
					//prepend last to first
					homeSlider.move.lastToFirst();
					homeSlider.move.animate(homeSlider.vars.pos, true);
				} else {
					//no appendingzings
					homeSlider.move.animate(homeSlider.vars.pos, false);
				}
				homeSlider.move.currentClass($curr.prev());

			}

        //if the slider is currently peeking, remove peek
        homeSlider.peek.move(0);
			//update the bottom nav
			homeSlider.nav.update();

		},

		toSlide: function($elm){

			var pos =  homeSlider.helpers.getPercent($elm.attr('style')) * -1;

			//if moving to the beginning of the stack
			if ( $elm.is(':first-child') ) {
				homeSlider.move.lastToFirst();
				homeSlider.move.currentClass($elm);
				homeSlider.move.animate(pos, true);

			//if moving to the end of the stack
			} else if ( $elm.is(':last-child') ) {
				homeSlider.move.firstToLast();
				homeSlider.move.currentClass($elm);
				homeSlider.move.animate(pos, true);

			//if moving to the middle of the stack
			} else {
				homeSlider.move.currentClass($elm);
				homeSlider.move.animate(pos, false);
			}

			//update the bottom nav
			homeSlider.nav.update();
			//update the tray positon
			homeSlider.vars.pos = pos;

		},

		//updates current class to requested slide
		currentClass: function($elm){
			$elm.addClass('current').siblings().removeClass('current');
		},

		//animation of the slider tray
		animate: function(pos, flush){
			$('.slider .tray').animate({'left': pos+'%'}, homeSlider.vars.duration, 'easeInOutQuart', function(){
				if (flush) {
					homeSlider.move.flush();
				} else {
					homeSlider.helpers.unlock();
				}
			});
		},

		//dupe first slide to end of stack + mark first slide for removal
		firstToLast: function(){
			var $elm = $('.slider section:first-child');
				pos = homeSlider.helpers.getPercent($('.slider section:last-child').attr('style')) + 100;
				$clone = $elm.clone();
			$elm.addClass('remove');
			$clone.removeAttr('style').css({'left': pos+'%' }).appendTo($('.slider .tray'));
		},

		//dupe last slide to beginning of stack + mark last slide for removal
		lastToFirst: function(){
			var $elm = $('.slider section:last-child');
				pos = homeSlider.helpers.getPercent($('.slider section:first-child').attr('style')) - 100;
				$clone = $elm.clone();
			$elm.addClass('remove');
			$clone.removeAttr('style').css({'left': pos+'%' }).prependTo($('.slider .tray'));
		},

		//remove old slide from stack
		flush: function(){
			$('.slider .tray section.remove').remove();
			homeSlider.helpers.unlock();
		}

	}

};

var helper = {
  
  init: function(){
    helper.center();
    $(window).resize(helper.center);
  },
  
  center: function(){
    $.each($('.slider section img'), function(i, elm){
      $(elm).css({marginTop:-$(elm).height()/2, top:'50%', position:'relative'});
    })
  }
}

homeSlider.init();
helper.init();
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console