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

              
                <script src="//vto-advanced-integration-api.fittingbox.com/index.js" type="text/javascript"></script>

<div class="wrapper">
  <div>
    <button onclick="openVto()">Start the VTO experience (in Faceshape)</button>
    <button onclick="getFaceshape()">Trigger Faceshape analysis</button>
    <button onclick="stopVto()">Stop the VTO experience</button>  
  </div>
  
  <div class="lineContainer">
    <span>Faceshape status: </span><span class="faceshapeModeValue"></span>
  </div>
  
  <div id="fitmix-container"></div>
</div>

<div class="info">
  <div class="errorEntry"><a>10</a> <a>Detection error</a></div>
  <div class="errorEntry"><a>11</a> <a>No face detected</a></div>
  <div class="errorEntry"><a>12</a> <a>Detection server connection error</a></div>
  <div class="errorEntry"><a>20</a> <a>Faceshape server connection error</a></div>
  <div class="errorEntry"><a>21</a> <a>Empty faceshape</a></div>
  <div class="errorEntry"><a>30</a> <a>Not in faceshape mode</a></div>
  <div class="errorEntry"><a>31</a> <a>FBxLive version not compatible</a></div>
  <div class="errorEntry"><a>102</a> <a>Face not aligned to the left / right</a></div>
  <div class="errorEntry"><a>103</a> <a>Face not aligned up / down</a></div>
  <div class="errorEntry"><a>104</a> <a>Face not aligned up / down and left / right</a></div>
  <div class="errorEntry"><a>105</a> <a>Face edge not detected</a></div>
  <div class="errorEntry"><a>106</a> <a>Face shape cannot be classified</a></div>
</div>
              
            
!

CSS

              
                html, body {
  margin: 0;
}

.wrapper {
  --padding: 0.5rem;
  height: calc(100vh - var(--padding) * 2);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: var(--padding);
}

#fitmix-container {
  width: min(500px, 90vw);
  flex: 1;
  display:none;
}

.info {
  position: absolute;
  left: 540px;
  top: 50px;
  border: 1px solid black;
  padding: 14px;
}

.errorEntry > a:first-child {
  display: inline-block;
  width: 40px;
}
              
            
!

JS

              
                var params = { 
  apiKey: 'TBVAcXitApiZPVH791yxdHbAc8AKzBwtCnjtv6Xn',
  frame: '8053672909258',
  onStopVto: hide,
  
  onGetFaceshape: function (data) {
    console.log("onGetFaceshape", data);
    var faceshapeValue = document.querySelector(".faceshapeModeValue");
    if (data.errorCode) {
      faceshapeValue.textContent =
        "Error - Code " +
        data.errorCode +
        " (" +
        data.errorDetail + ")";
    } else {
      faceshapeValue.textContent =
        "Dominant shape = " + data.faceShape + " (full results: " + toPercentage(data.confidence.heart) + ", " + toPercentage(data.confidence.long) + ", " + toPercentage(data.confidence.oval) + ", " + toPercentage(data.confidence.rectangle) + ", " + toPercentage(data.confidence.square) + ", " + toPercentage(data.confidence.triangle) + ")";
    }
  }
};

window.onload = function() {  
  window.fitmixInstance = FitMix.createWidget('fitmix-container', params, function() {
    console.log('FitmixWidget creation complete!');
  });
}

var toPercentage = function (value) {
  return "" + Math.round(value*100) + "%";
}

var getFaceshape = function () {
  fitmixInstance.getFaceshape();
  document.querySelector(".faceshapeModeValue").textContent =
    "getFaceshape in progress...";
};

const fitmix = document.getElementById("fitmix-container")

function hide(){
  fitmix.style.display= 'none';
}

function show(){
  fitmix.style.display= 'block';
}

function openVto(){
  fitmixInstance.startVto('faceshape')
  show()
}

function stopVto(){
  fitmixInstance.stopVto()
}
              
            
!
999px

Console