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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                %p.text-center{style: "margin-bottom:20px;"}
  Click and drag the image around
.container

              
            
!

CSS

              
                
              
            
!

JS

              
                ImageControl = do ->
  ->
    @init = (args) ->
      @originalArgs = args

      mainContainer = $(args.container).css(
        position: 'relative'
        'max-width': args.containerSize
        height: args.containerSize
        overflow: 'hidden'
      )

      imageContainer = $('<div />').css(
        width: '97%'
        height: '97%'
        top: '4%'
        position: 'relative'
        overflow: 'hidden'
        cursor: 'move'
      )

      
      patternImage = $('<div />').attr(
        class: 'pattern-background-image'
      ).css(
        left: 0
        top: 0
        width: '100%'
        height: '100%'
        position: 'absolute'
        'background-size': "70%"
        'background-repeat': 'repeat'
        'background-position': "0% 0%"
        'background-image': "url('#{args.backgroundPattern}')"
      )

      zoomSliderContainer = $("<div />").attr(
        class: 'range-slider'
      ).css(
        top: 0
        right: 0
        width:'100%'
        height: '2%'
        'z-index': 100000
        position: 'absolute'
        'text-align': 'center'
      )

      zoomSlider = $("<input type='range' step='1' min='20' max='99' value='70'>").css(
        width: '50%'
        display: 'inline-block'
        '-webkit-appearance': 'none'
        'background': '#eee'
        '-webkit-tap-highlight-color': 'rgba(255, 255, 255, 0)'
      )

      zoomSliderContainer.append zoomSlider
      zoomSliderContainer.append "<span> <---- Zoom control </span>"
      imageContainer.append patternImage
      mainContainer.append imageContainer
      mainContainer.append zoomSliderContainer

      @zoomSlider = zoomSlider
      @patternImage = patternImage

      
      zoomSlider.on 'input change', (e) ->
        zoomVal = $(this).val()
        imageContainer.find('.pattern-background-image').css(
          'background-size': ""+zoomVal+"%"
        )

   
      imageContainer.on 'mousedown touchstart', (e) ->
        e.preventDefault()

        patternBackground = $(this).find('.pattern-background-image')
        mousedown =
          x: e.originalEvent.pageX || e.originalEvent.touches[0].pageX
          y: e.originalEvent.pageY || e.originalEvent.touches[0].pageY

        elepos =
          x: parseFloat(patternBackground.css("backgroundPosition").split(" ")[0].replace('%',''))
          y: parseFloat(patternBackground.css("backgroundPosition").split(" ")[1].replace('%',''))

        
        $(document).on 'mouseup touchend', (e) ->
          $(document).unbind 'mousemove touchmove'

        $(document).on 'mousemove touchmove', (e) ->
          mousepos =
            x: e.originalEvent.pageX || e.originalEvent.changedTouches[0].pageX || mousedown.x
            y: e.originalEvent.pageY || e.originalEvent.changedTouches[0].pageY || mousedown.y
            
          if mousedown != mousepos
            xpos = (100 * (mousepos.x - mousedown.x)) / patternBackground.width()
            ypos = (100 * (mousepos.y - mousedown.y)) / patternBackground.width()

            patternBackground.css
              'background-position': "#{xpos}% #{ypos}%"

          return
    return

  
$(document).ready ->
  imageControl = new ImageControl
  
  imageControl.init
    container: '.container'
    containerSize: '500px'
    backgroundPattern: 'https://cookieshq.co.uk/images/2016/06/28/background-image.jpg'
  

  return
              
            
!
999px

Console