Pen Settings

HTML

CSS

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

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!-- All photos copyright Jeff Garris -->
<body>
    <div class="slider-wrapper">
        <div class="slider"></div>
        <div class="bullets"></div>
    </div>
</body>
              
            
!

CSS

              
                $light-gray: #ccc;
$medium-gray: #777;
$dark-gray: #222;

$bullet-width: 45px;
$bullet-height: 8px;

body {
    background: $dark-gray;
}

.slider-wrapper {
    border: 1px solid $medium-gray;
    background: transparent;
    width: 750px;
    height: 500px;
    margin: auto;
    margin: auto;
    z-index: 20;
}

.slider {
    position: relative;
    height: 500px;
    margin: auto;
    z-index: 20;
}

.slide {
  background: $dark-gray;
  display: none;
  position: absolute;
  top: 0px;
  left: 0px;
  z-index: 20;
  
  &:first-child {
    display: block;
    position: absolute;
    top: 0px;
    left: 0px;
    z-index: 20;
  }
}

.slide-image {
    margin: auto;
    display: block;
    width: 750px;
    height: 500px;
    z-index: 20;
}

.bullets {
    display: flex;
    justify-content: center;
    margin: auto;
    margin-top: 10px;
}

.bullet {
    background-color: white;
    width: $bullet-width;
    height:$bullet-height;
    cursor: pointer;
    transition: background-color .1s;
  
  &:hover {
    background-color: $light-gray;
  }
  
  &:not(:first-child) {
    margin-left: 10px;
  }
  
  &.selected {
    background-color: $medium-gray;
  }
}
              
            
!

JS

              
                // Flickr Album JSON URL
// https://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=3bf1ac3b0cfa8b508aef75e92071d1e8&photoset_id=72157628222699421&user_id=68940242@N06&extras=url_o&format=json&nojsoncallback=1

var userId = "68940242@N06";
var apiKey = "3bf1ac3b0cfa8b508aef75e92071d1e8";
var photoSetId = "72157628222699421";
var method = "flickr.photosets.getPhotos";
var limit = 10;
var photosUrl =
  "https://api.flickr.com/services/rest/?method=" +
  method +
  "&api_key=" +
  apiKey +
  "&photoset_id=" +
  photoSetId +
  "&user_id=" +
  userId +
  "&extras=url_o&format=json&nojsoncallback=1&per_page=" +
  limit;

var photos;

$.ajax({
  url: photosUrl,
  context: document.body
}).done(function(data) {
  photos = data.photoset.photo;

  setupSlider();
  setupEvents();
});

function setupSlider() {
  var files;
  var $slider = $(".slider");

  photos.map(photo => {
    var $slide = $("<div>", { class: "slide" });
    var $img = $("<img>", { class: "slide-image", src: photo.url_o });
    var $bullet = $("<div>", { class: "bullet" });

    // Set up slides
    $slider.append($slide);
    $slide.append($img);
    
    // Set up bullets
    $(".bullets").append($bullet);
  });
  
  $(".bullet:first-child").addClass("selected"); // Sets first bullet as selected bullet
}

var slideIndex = 1, // Sets index number for first slide (+1 for every slide thereafter)
  slideChangeSpeed = 5000, // Time between slide change in milliseconds
  slideFadeIn = 1400, // Fade in time in milliseconds
  slideFadeOut = 1400; // Fade out time in milliseconds

// Start slideshow
var beginSlideShow = setInterval(function() {
  var $slider = $(".slider");
  var $sliderChildren = $slider.children();

  $sliderChildren
    .fadeOut(slideFadeOut)
    .eq(slideIndex)
    .fadeIn(slideFadeIn);
  $(".bullet")
    .eq(slideIndex)
    .addClass("selected")
    .siblings()
    .removeClass("selected");
  slideIndex++;
  if (slideIndex === $sliderChildren.length) {
    slideIndex = 0;
  }
}, slideChangeSpeed);

// Show specific slide based on bullet choice and stop slideshow
function setupEvents() {
  var $slider = $(".slider");
  var $sliderChildren = $slider.children();

  $(".bullet").click(function() {
    $this = $(this);

    clearInterval(beginSlideShow);
    $sliderChildren.fadeOut(slideFadeOut); // Fades out all slides
    $sliderChildren.eq($(this).index()).fadeIn(slideFadeIn); // Uses the selected bullet's index to fade in the corresponding slide
    $(this)
      .addClass("selected")
      .siblings()
      .removeClass("selected"); // Sets all bullets to unselected, then sets the selected bullet to selected
  });
}

              
            
!
999px

Console