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

              
                <p>Press the button when the card is in the middle to advance!</p>
<button type ="button" id="btnTest2" onclick="changeImage()">Change Picture</button>

<p id="resultVarUpdate"></p>

<container>
<div class="boxred" id="boxred">
  <div class="boxyellow" id="boxyellow">
    <img style="max-width:110%; max-height:110%; transform: translateX(20%); " src="https://raw.githubusercontent.com/vinagava/vinagava/master/Deficit/Graphics/ChopGame/Photo_Powder1.png" id="imgReplace"></img>
  </div> 
  <div class="boxgreen" id="boxgreen">
    <img style="max-width:100%; max-height:100%;"src="https://raw.githubusercontent.com/vinagava/vinagava/master/Deficit/Graphics/ChopGame/Photo_Hand.png" id="handmove"></img>
  </div>       

<div class="boxgreen" id="boxgreenStop">
    <img style="max-width:100%; max-height:100%;"src="" id="handmoveDone"></img>
</div>


</div>
</container>
</br>

              
            
!

CSS

              
                /* #imgBox{
        max-width: 100%;
        max-height: 100%;        
} */

#boxred {
  /* height: 50%;
  width: 70%; */
  height:20vw;
  width: 60vw;
 
  position: relative;
  background-color: red;
  z-index: 1;
  margin: auto;
}
  
 #boxgreen {
  height: 100%;
  width: 33%;
  position: absolute;
  z-index: 2;
  /*background-color: green; */
animation: movegreen 3s ease-in-out infinite; 
  /* animation-delay: 2s; */
  animation-direction: alternate;
}

@keyframes movegreen {
     0% {transform: translateX(0%)} 
	100% {transform: translateX(230%)}
}

 #boxgreenStop {
  height: 100%;
  width: 33%;
  position: absolute;
  z-index: 2;
   left:80%;
}

#boxyellow {
  height: 100%;
  width: 33%;
  position: absolute;
  /*z-index: 2;*/
  left: 34%;
  background-color: yellow;
}

button {
  margin-top: 0px;
  line-height: 25px;
  font-weight: bold;
  padding: 0 80px;
  background: salmon;
  border: none;
}

/*
body{
  font-family: arial;
  font-size: 20px;
  padding: 5% 24%;
}
*/
              
            
!

JS

              
                document.addEventListener("DOMContentLoaded", function() {
  var btnTest2 = document.getElementById('btnTest2');
  init();
  });

function init()
{ 
  document.getElementById("btnTest2").onclick= changeImage;  
  //Changes the picture when you click
function changeImage() {  
if(onTarget == 0 && imgCount == 1 && pause ==0)
        { 
 imgCount++;
 pause++;
          document.getElementById("imgReplace").src = "https://raw.githubusercontent.com/vinagava/vinagava/master/Deficit/Graphics/ChopGame/Photo_Powder2.png";
        }
else if  (onTarget == 0 && imgCount == 2 && pause ==0){
  
imgCount++; 
pause++; 
          document.getElementById("imgReplace").src = "https://raw.githubusercontent.com/vinagava/vinagava/master/Deficit/Graphics/ChopGame/Photo_Powder3.png";
        }
  else if  (onTarget == 0 && imgCount == 3 && pause ==0){
    
imgCount++; 
pause++; 
          document.getElementById("imgReplace").src = "https://raw.githubusercontent.com/vinagava/vinagava/master/Deficit/Graphics/ChopGame/Photo_Powder4.png";
        }
  else if  (onTarget == 0 && imgCount == 4 && pause ==0){
    
imgCount++; 
pause++;
    
    var endTimerCount = setInterval(endTimer, 1000); 
          document.getElementById("imgReplace").src = "https://raw.githubusercontent.com/vinagava/vinagava/master/Deficit/Graphics/ChopGame/Photo_Powder5.png";
  }    
}

//Vars
//Checks which state you're in, and if you're over the target
var imgCount =1;
var onTarget =1;
var pause =0;
var endCount =0;

/**
 * Gets computed translate values
 * @param {HTMLElement} element
 * @returns {Object}
 */
function getTranslateValues (boxgreen) {
  const style = window.getComputedStyle(boxgreen)
  const matrix = style.transform || style.webkitTransform || style.mozTransform

  // No transform property. Simply return 0 values.
  if (matrix === 'none') {
    return {
      x: 0,
      y: 0,
      z: 0
    }
  }

  // Can either be 2d or 3d transform
  const matrixType = matrix.includes('3d') ? '3d' : '2d'
  const matrixValues = matrix.match(/matrix.*\((.+)\)/)[1].split(', ')

  // 2d matrices have 6 values
  // Last 2 values are X and Y.
  // 2d matrices does not have Z value.
  if (matrixType === '2d') {
    return {
      x: matrixValues[4],
      y: matrixValues[5],
      z: 0
    }
  }
}

//greenbox width
let greenbox = document.getElementById('boxgreen');
let gwth = window.getComputedStyle(greenbox, null).getPropertyValue("width");

//redbox width
let redbox = document.getElementById('boxred');
let wth = window.getComputedStyle(redbox, null).getPropertyValue("width");

//Button Stuff
function checkButton() {
  const {x, y, z} = getTranslateValues(boxgreen);
  let wth = window.getComputedStyle(redbox, null).getPropertyValue("width");
}

var myVarTest = setInterval(boxtimertest, 100);

function boxtimertest() {
 const {x, y, z} = getTranslateValues(boxgreen);
  let wth = window.getComputedStyle(redbox, null).getPropertyValue("width");
  let gwth = window.getComputedStyle(greenbox, null).getPropertyValue("width");  

  var num1 = parseInt(wth, 10);
  var num2 = parseInt(x, 10);
  var num3 = parseInt(gwth, 10);
  var q = (num1 - num2);
  var gmid = (num3/2);
  var gmidd = (Math.floor(num2 + (num3/2)));
  var thirty = (Math.floor(num1 * (36/100)));
  var sixty = (Math.floor(num1 * 36/100)*2);
  
if (gmidd < thirty) { 
 onTarget =1; 
 pause =0;
    document.getElementById("resultVarUpdate").innerHTML = ("Zone(updated): ") + "Red" + (" | onTarget:  ") + onTarget + (" | pause: ") + pause +endCount;
}  
  
 else if (gmidd > sixty) { 
onTarget = 1;
pause = 0;
   document.getElementById("resultVarUpdate").innerHTML =("Zone(updated): ") + "Red" + (" | onTarget:  ") + onTarget + (" | pause: ") + pause +endCount;
 }
  
   else if (gmidd > thirty && gmid < sixty) { 
onTarget=0;
//pause=0;
     document.getElementById("resultVarUpdate").innerHTML =("Zone(updated): ") + "Green" + (" | onTarget:  ") + onTarget + (" | pause: ") + pause +endCount;
 }
}

//Pseudo timer for the end
function endTimer() {
 endCount++; 
}



var endListener = setInterval(end, 100); 

function end() {
  if  (endCount == 2){
    
document.getElementById("handmove").src ="";    
   document.getElementById("handmoveDone").src ="https://raw.githubusercontent.com/vinagava/vinagava/master/Deficit/Graphics/ChopGame/Photo_Hand.png";
        }
}
}
              
            
!
999px

Console