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

              
                <div class="container">
  <div id="windmill">
    <div id="sails">
      <img src="http://www.claraalder.com/assets/img/windmill_sail.png" alt="Roundhill Logo" class="img-sail" />
    </div>
  </div>
</div>
              
            
!

CSS

              
                body {
  background-color: #1D1D1D;
}

.container {
  margin: 40px;
}

#windmill {
  background-image: url("http://www.claraalder.com/assets/img/windmill_building.png");
  background-position: center;
  background-repeat: no-repeat;
  background-size: 350px 350px;
  height: 350px;
  width: 350px;
  margin: auto;
}

.img-sail {
  display: block;
  margin: auto;
  height: 262.5px;
  width: 262.5px;
  padding: 40px;
}

/* 
#sails {
  animation: spin 5s ease-in 3;
} */

/*
@keyframes spin {
  
 100% {
    transform: rotate(360deg);
  }
  
} */
              
            
!

JS

              
                //create a variable that won't be reassigned at any point
//using the gsap to method to spin the sail. it starts paused. its rotation is a constant speed. 
//repeat -1 means infinite
//duration 2 means two seconds
const sails = gsap.to('#sails', {
  rotation: 360,
  duration: 2,
  ease: 'none',
  repeat:-1,
  paused: true,
  // can do stuff like transformOrigin: 'top center' or '50%' or 'center' (short for center center)
  transformOrigin: '50%'
  
  
})

//create a variable that won't be reassigned at any point
const windmill = document.querySelector('#windmill')

//creates a named function that can be referred to elsewhere, which makes the sails move
function playAnimation() {
  sails.play()
}

//creates a named function that can be referred to elsewhere, which makes the sails pause
function pauseAnimation() {
  sails.pause()
}

//adding an event listener to our windmill which listens for a mouse hover and then calls the functions to move the sails
//dom scripting is for webpages - selecting the elements on the webpage
windmill.addEventListener('mouseenter', playAnimation)
//adding an event listener to our windmill which listens for a mouse leaving and then calls the functions to pause the sails
windmill.addEventListener('mouseleave', pauseAnimation)
              
            
!
999px

Console