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.

            
              <button>Hover for a new image</button>
            
          
!
            
              html, body {
  min-height: 400px;
}

button {
  background: #ddd;
  border: none;
  font-size: 20px;
  padding: 10px 20px;
}

.tippy-tooltip.ajax-theme {
  position: absolute;
  width: 200px;
  padding: 0;
  overflow: hidden;
}

.tippy-tooltip.ajax-theme img {
  display: block;
  max-width: 100%;
}

/* 
We need to "pin" the tooltip absolutely to the bottom or top of the popper element depending on the placement. Note: this overrides the `distance` option. You can change `0` to be whatever you want. 
*/
.tippy-popper[x-placement^='top'] .tippy-tooltip.ajax-theme {
  top: auto !important;
  bottom: 0;
}

.tippy-popper[x-placement^='bottom'] .tippy-tooltip.ajax-theme {
  bottom: auto !important;
  top: 0;
}
            
          
!
            
              const INITIAL_CONTENT = '<div style="margin:5px 0;">Loading...</div>'

tippy('button', {
  content: INITIAL_CONTENT,
  animation: 'fade',
  animateFill: false,
  duration: 200,
  theme: 'ajax',
  onShow(tip) {
    if (tip.state.isFetching === true || tip.state.canFetch === false) {
      return
    }

    tip.state.isFetching = true
    tip.state.canFetch = false

    const { popper } = tip
    const { tooltip, content } = tip.popperChildren

    // Because the tooltip has `position: absolute`,
    // it no longer affects the parent popper's layout.
    // We need to explicitly give it a width.
    popper.style.width = '200px'

    fetch('https://unsplash.it/200/?random')
      .then(response => response.blob())
      .then(blob => {
        tip.state.isFetching = false

        const url = URL.createObjectURL(blob)

        if (!tip.state.isVisible) {
          return
        }

        const img = new Image()
        img.width = 200
        img.height = 200
        img.src = url

        // Wait until the height transition has finished before
        // fading the content in. Since we have `overflow: hidden`
        // on the tooltip this isn't actually needed, but if you
        // have an arrow element it will be.
        if (!tip._transitionEndListener) {
          tip._transitionEndListener = event => {
            if (event.target === event.currentTarget) {
              content.style.opacity = '1'
              tip.setContent(img)
            }
          }
        }
        tooltip.addEventListener('transitionend', tip._transitionEndListener)

        // Store the base height of the tooltip when it has the
        // initial Loading... content.
        if (!tip._baseHeight) {
          tip._baseHeight = tooltip.clientHeight
        }

        // Here is where we find out the height of the tooltip
        // when it has the content. We could technically hardcode
        // 200px as the value, but it's useful to know how to do
        // this with dynamic content.
        content.style.opacity = '0'
        // Temporarily set the image as the tooltip's content
        // so we can find out the final height of the tooltip.
        tip.setContent(img)
        const height = tooltip.clientHeight
        // Apply the height to the parent popper element.
        popper.style.height = height + 'px'
        // Reset the tooltip's height to the base height.
        tooltip.style.height = tip._baseHeight + 'px'
        // Cause reflow so we can start the height transition.
        void tooltip.offsetHeight
        // Start the transition.
        tooltip.style.height = height + 'px'
        // Remove the Loading... content and wait until the
        // transition finishes.
        tip.setContent('')
      })
      .catch(() => {
        tip.state.isFetching = false
      })
  },
  onHidden(tip) {
    tip.state.canFetch = true
    tip.setContent(INITIAL_CONTENT)
    const { tooltip } = tip.popperChildren
    tooltip.style.height = null
    tooltip.removeEventListener('transitionend', tip._transitionEndListener)
    tip._transitionEndListener = null
  }
})

            
          
!
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