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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              <script>
  // Add image address here
  var ystq_imageURL = 'https://s-media-cache-ak0.pinimg.com/736x/20/b1/c1/20b1c176a79a959332d8cb650e68c647.jpg',
    // Set to false (no quotes) to hide onboarding instructions
    ystqOnboarding = true,
    // if you change the timing of the animations,
		// the numbers in the style section below must
    // match those here
  	ystqOnboardingTiming = {
      veil         : 1500,
      swipe        : 1000,
      instructions : 250,
			// 'pause' is independent of the style section
      pause        : 750,
    };
</script>
<style>
  .ystq_veil{
    transition-duration: 1000ms;
  }

  [class*="ystq_swipe-"]{
    transition-duration: 1000ms;
  }

  .ystq_instructions{
    transition-duration: 250ms;
  }

  /* uncomment this in production *.
  /*.tinderquest,
  .tinderquest + label{
    display: none;
  }*/
  /* end uncomment */
</style>

  <div id="ystq_container"></div>

<form name="f1">
  <input type="radio" name="tinderquest" class="tinderquest" id="tinderquest_negative" value="0"><label for="tinderquest_negative">Disagree</label>
  <input type="radio" name="tinderquest" class="tinderquest" id="tinderquest_positive" value="1"><label for="tinderquest_positive">Agree</label>
  <!-- delete this in prodcution -->
  <button class="reset">Run again</button>
  <!-- end delete -->
</form>
            
          
!
            
              #ystq_container {
  width: 500px;
  margin: auto !important;
  display: block;
  height: 500px;
  position: relative;
  list-style-type: none;
  user-select: none;
}

.ystq_buddy {
  display: block;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 0 10px rgba(0,0,0,0.2);
  color: #fff;
  padding: 20px;
  width: 360px;
  height: 360px;
  top: 50px;
  left: 50px;
  position: absolute;
  cursor: ew-resize;
}

[class*="ystq_swipe-"]{
   transform: translateZ(0);
   backface-visibility: hidden;
   perspective: 1000;
   transform: translate3d(0, 0, 0) scale(0.8);
   transition: 1s ease-in;
   opacity: 0;
   z-index: 10;
}

.ystq_swipe-left {
  transform: rotate(-30deg);
  margin-left: -400px;
}

.ystq_swipe-right {
  transform: rotate(30deg);
  margin-left: 400px;
}

.ystq_avatar {
  background: #222;
  width: 100%;
  height: 100%;
  display: block;
  background-size: auto 160% !important;
  background-position: center;
  background-repeat: no-repeat;
}

.ystq_like,
.ystq_dislike {
  position: absolute;
  width: 50%;
  height: 50%;
  left: 50%;
  top: 50%;
  margin-left: -25%;
  margin-top: -25%;
  text-indent: -1000%;

  &:before,
  &:after{
    content: '';
    position: absolute;
  }
}

.ystq_like{
  &:before,
  &:after{
    background: green;
  }

  &:before{
    width: 25%;
    height: 100%;
    left: 50%;
    margin-left: 0;
    top: 0;
    transform: rotate(45deg);
  }

  &:after{
    width: 25%;
    height: 50%;
    left: 50%;
    margin-left: -35%;
    top: 42.5%;
    transform: rotate(-45deg);
  }
}


.ystq_dislike{
  &:before,
  &:after{
    background: red;
    width: 25%;
    height: 100%;
    left: 50%;
    margin-left: -12.5%;
    top: 0;
  }

  &:before{
    transform: rotate(45deg);
  }

  &:after{
    transform: rotate(-45deg);
  }
}

.ystq_veil{
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  background: rgba(0,0,0,0.5);
  cursor: default;
  z-index: 999;
  overflow: visible;
  opacity: 1;
  transition: opacity 1s ease-out;
}

.ystq_mask{
  position: absolute;
  width: 600px;
  height: 500px;
  margin-left: -120px;
  margin-top: -70px;
  background: #fff;
  box-shadow: 0px 0px 62px 45px rgba(255,255,255,1);
  border-radius:50%;
  z-index: -1;
}

.ystq_clone{
  left: 50%;
  z-index: 2;
  cursor: default;

  &.ystq_swipe-left{
     margin-left: -600px;
  }

  &.ystq_swipe-right{
     margin-left: 200px;
  }
}

.ystq_instructions{
  font-family: Impact, Arial;
  color: #fff;
  width: 100%;
  text-align: center;
  margin-top: 20px;
  text-stroke: 2px black;
  text-shadow:
    -1px 0 black, 0 1px black,
    1px 0 black, 0 -1px black,
    0 0 1px black;
  transition: all 0.25s ease-out;
  z-index: 999;
}

.ystq_transparent{
  opacity: 0;
}

.ystq_shift-left{
  margin-left: -300px;
}

.ystq_shift-right{
  margin-left: 300px;
}
            
          
!
            
              var TinderQuest = function (elementId, onboarding, onboardingTiming) {
  'use strict';
  
  var tQ = this;

  tQ.container = document.getElementById( elementId );
console.log(elementId, tQ.container)
  tQ.buddy     = document.createElement('div');//document.getElementsByClassName('ystq_buddy')[0];
  tQ.avatar    = document.createElement('div');//document.getElementsByClassName('ystq_avatar')[0];
  tQ.status    = document.createElement('div');
  tQ.mc        = new Hammer(tQ.buddy);
  tQ.timing    = {
    veil         : onboardingTiming.veil         || 1000,
    swipe        : (onboardingTiming.swipe       || 1000) + 250,
    instructions : onboardingTiming.instructions || 250,
    pause        : onboardingTiming.pause        || 500,
    beat         : 5,
  };
  
  
  tQ.buddy.classList.add('ystq_buddy');
  tQ.container.appendChild(tQ.buddy);

  tQ.avatar.classList.add('ystq_avatar');
  tQ.avatar.style.backgroundImage = 'url(' + ystq_imageURL + ')';
  tQ.buddy.appendChild(tQ.avatar);

  // listen to events...

  tQ.mc.on("panleft panright", function(ev) {
    var direction = ev.type.replace('pan', '');

    tQ.status.classList.add('ystq_status');

    if(direction == 'left') {
      document.f1.tinderquest.value = '0';
      tQ.swipeLeft();
    }

    if(direction == 'right') {
      document.f1.tinderquest.value = '1';
      tQ.swipeRight();
    }
  });
  
  if(onboarding) {
    tQ.veil         = document.createElement('div');
    tQ.mask         = document.createElement('div');
    tQ.instructions = document.createElement('h1');

    tQ.clone        = tQ.buddy.cloneNode(true);

    tQ.position     = tQ.buddy.getBoundingClientRect();

    tQ.veil.classList.add('ystq_transparent');
    tQ.veil.classList.add('ystq_veil');
    document.body.appendChild(tQ.veil);
    tQ.veil.addEventListener('click', function(event){
      tQ.cancelBubbling(event);
    });
    tQ.veil.addEventListener('touch', function(event){
      tQ.cancelBubbling(event);
    });

    tQ.mask.classList.add('ystq_mask');
    tQ.veil.appendChild(tQ.mask);

    tQ.clone.classList.add('ystq_clone');
    tQ.clone.style.left = tQ.position.left + 'px';
    tQ.clone.style.top  = tQ.position.top + 'px';
    tQ.mask.style.left  = tQ.position.left + 'px';
    tQ.mask.style.top   = tQ.position.top + 'px';

    tQ.instructions.classList.add('ystq_instructions');
    tQ.instructions.classList.add('ystq_transparent');
    tQ.instructions.classList.add('ystq_shift-left');
    tQ.veil.appendChild(tQ.instructions);


    tQ.tutorialOne = function () {

      // Fade in veil
      tQ.veil.classList.remove('ystq_transparent');
      
      // Wait for fade in, then add instructions
      setTimeout(function () {

        tQ.instructions.classList.remove('ystq_transparent');
        tQ.instructions.classList.remove('ystq_shift-left');

        // pause for instructions then swipe right
        setTimeout(function () {
          tQ.instructions.classList.add('ystq_transparent');
          tQ.instructions.classList.add('ystq_shift-right');
          tQ.clone.classList.add('ystq_swipe-right');
          tQ.clone.appendChild(tQ.status);
          tQ.status.classList.add('ystq_status');
          tQ.status.classList.add('ystq_like');
          tQ.status.innerHTML = 'Agree';

          // wait for swipe to complete then reset
          setTimeout(function () {
            tQ.resetTutorial();

            // pause then trigger part two
            setTimeout(tQ.tutorialTwo, tQ.timing.pause);
          }, tQ.timing.swipe);
        }, tQ.timing.instructions + tQ.timing.pause);
      }, tQ.timing.veil);
    }

    tQ.tutorialTwo = function () {
      // Reset instructoms
      tQ.instructions.parentNode.removeChild(tQ.instructions);
      tQ.instructions.innerHTML = 'Swipe left for No';
      tQ.veil.appendChild(tQ.instructions);
      
      // Wait a beat then bring in instruction
      setTimeout(function (){
        tQ.instructions.classList.remove('ystq_transparent');
        tQ.instructions.classList.remove('ystq_shift-right');
      }, tQ.timing.beat);

      // pause before swiping left
      setTimeout(function () {
        tQ.instructions.classList.add('ystq_transparent');
        tQ.instructions.classList.add('ystq_shift-left');
        tQ.clone.classList.add('ystq_swipe-left');
        tQ.clone.appendChild(tQ.status);
        tQ.status.classList.add('ystq_status');
        tQ.status.classList.add('ystq_dislike');
        tQ.status.innerHTML = 'Disagree';

        // wait for swipe then fade out veil
        setTimeout(function () {
          tQ.veil.classList.add('ystq_transparent');
          // wait for fade then delete veil
          setTimeout(function () {
            tQ.veil.parentNode.removeChild(tQ.veil);
            tQ.resetTutorial();
          }, tQ.timing.veil);
        }, tQ.timing.swipe);
      }, tQ.timing.pause);
    }
    
    tQ.resetTutorial = function () {
      tQ.veil.appendChild(tQ.clone);
      tQ.clone.classList.remove('ystq_swipe-right');
      tQ.clone.classList.remove('ystq_swipe-left');
      tQ.instructions.innerHTML = 'Swipe right for Yes';
      tQ.status.className = '';
      if(tQ.status.parentNode != null) {
        tQ.status.parentNode.removeChild(tQ.status);
      }
    }
  
    tQ.cancelBubbling = function (event) {
      event.stopPropagation();
      event.preventDefault()
    }
    
    tQ.resetTutorial();
    
    // Pause before commencing
    setTimeout(tQ.tutorialOne, tQ.timing.pause);
  }
  
  tQ.swipeLeft = function () {
      tQ.buddy.classList.add('ystq_swipe-left');
      tQ.status.classList.add('ystq_dislike');
      tQ.status.innerHTML = 'Disagree';
      tQ.buddy.appendChild(tQ.status);
  }
  
  tQ.swipeRight = function () {
    
      tQ.buddy.classList.add('ystq_swipe-right');
      // Reset status classes as onboarding messes them up and doing it in resetTutorial() doesn't work for no apparent reason! 
      tQ.status.className = '';
      tQ.status.classList.add('ystq_status');
      tQ.status.classList.add('ystq_like');
      tQ.status.innerHTML = 'Agree';
      tQ.buddy.appendChild(tQ.status);
  }
}

// https://github.com/cms/domready
var domReady=function(){function e(){a?document.removeEventListener("DOMContentLoaded",e,!0):"complete"===document.readyState&&document.detachEvent("onreadystatechange",e),g()}function f(){if(!b){try{document.documentElement.doScroll("left")}catch(a){return void window.setTimeout(arguments.callee,15)}g()}}function g(){if(!b){b=!0;for(var a=d.length,c=0;c<a;c++)d[c].call(document)}}var a=!!document.addEventListener,b=!1,c=!1,d=[];if(a)document.addEventListener("DOMContentLoaded",e,!0),window.addEventListener("load",g,!1);else{document.attachEvent("onreadystatechange",e),window.attachEvent("onload",g);try{c=null===window.frameElement}catch(a){}document.documentElement.doScroll&&c&&f()}return function(a){return b?a.call(document):d.push(a)}}();

domReady(function() {
  new TinderQuest('ystq_container', ystqOnboarding, ystqOnboardingTiming);
});
            
          
!
999px
Loading ..................

Console