Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <svg id="speelVeld" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
     viewBox="0 0 1366 706.8" style="enable-background:new 0 0 1366 706.8;" xml:space="preserve">
<style type="text/css">
    .st0{fill:#FF5000;}
    .st1{fill:#3535D4;}
    .st2{fill:none;stroke:#3535D4;stroke-width:1.5;stroke-miterlimit:10;}
    .st3{fill:#ffffff;}
</style>
<g id="speelveldClick">
        <rect x="30" y="29" class="st0" width="1306" height="645.7"/>
</g>
<g id="moveX">
        <path class="st1" d="M-85.8,29V9h171v20H-85.8z M85.8,694.7v-20h-171v20H85.8z"/>
        <!-- <line class="st2" x1="0" y1="59" x2="0" y2="645.2"/> -->
</g>
<g id="moveY">
        <path class="st1" d="M30,85H10V-86h20V85z M1356-86h-20V85h20V-86z"/>
        <!-- <line class="st2" x1="1306" y1="0" x2="60" y2="0"/> -->
</g>
<circle id="ball" class="st3" cx="683" cy="353.4" r="18"/>
</svg>
              
            
!

CSS

              
                body{
	background-color: #FF5000;
}

#speelveldClick{
	cursor: pointer;
}
              
            
!

JS

              
                //refresh when the ball is out of sight
var ease = 0.15;

var speelVeld = document.querySelector("#speelVeld");
var moveX = document.querySelector("#moveX");
var moveY = document.querySelector("#moveY");
var bg = document.querySelector("#speelveldClick");

var mouse = speelVeld.createSVGPoint();
var pos = { x: 0, y: 0 };

var fieldBox = speelVeld.getBBox();
var Xbox = moveX.getBBox();
var Ybox = moveY.getBBox();
var viewXhalf = fieldBox.width/2;
var viewYhalf = fieldBox.height/2;
var xboxHalf = Xbox.width/4;
var yboxHalf = Ybox.height/4;

var ball = document.querySelector("#ball");
var ballBox = ball.getBBox();
var setBall = ballBox.width/2;
var tlBall = new TimelineMax();

/*
var tlX = new TimelineMax();
var tlY = new TimelineMax();

window.onload = function(e){
    
  tlX.set(moveX, {
    x: viewXhalf-xboxHalf
  });

  tlY.set(moveY, {
    y: viewYhalf-yboxHalf
  });
}
*/

bg.onclick = function(e){
    mouse.x = e.clientX;
    mouse.y = e.clientY;
};


TweenMax.ticker.addEventListener("tick", update);
function update() {
 
var point = mouse.matrixTransform(speelVeld.getScreenCTM().inverse());
  
  pos.x += (point.x - pos.x) * ease; 
  pos.y += (point.y - pos.y) * ease;
  
  TweenLite.set(moveX, {
    x: pos.x
  });

  TweenLite.set(moveY, {
    y: pos.y
  });
}

TweenMax.ticker.addEventListener("tick", mBall);
function mBall() {
tlBall
  .set(ball, {x: setBall ++}); //is there a way to speed this up?
}


//below is a quick attempt to reset the ball if it's beyond the viewbox of the svg; I did not figure out yet how to do that 

/*
function resetBall(){
if ballBox.x => fieldBox.x{
  tlBall.kill();
  }
}
*/

















              
            
!
999px

Console