Ползунок для перехода по ссылке go - PullRequest
0 голосов
/ 26 мая 2020

У меня небольшая проблема с этой кнопкой-ползунком. (Здесь я использовал ползунок диапазона, чтобы он работал и на мобильных устройствах.) Ползунок должен немного подпрыгнуть, чтобы указать, что вы можете сдвинуть кнопку, и в конце ползунка он должен go, чтобы ссылка. Я бы хотел, чтобы он тоже перестал подпрыгивать при наведении, но это не так важно.

К сожалению, есть ряд проблем: Chrome: * Большой палец не отскакивает, а переходит по ссылке. Firefox: Большой палец отскакивает, иногда выдает предупреждение «Заблокировано политикой X-Frame-Options». И он не возвращается к началу.

Safari: палец отскакивает, но не go на ссылку.

Мои JS навыки очень недостаточны, поэтому я предположение, что может вызвать некоторые проблемы.

$().ready(function() {
    var inputRange = document.getElementsByClassName('pullee')[0],
    maxValue = 150, // the higher the smoother when dragging
    speed = 12, // thanks to @pixelass for this
    currValue, rafID;

// set min/max value
inputRange.min = 0;
inputRange.max = maxValue;

// listen for unlock
function unlockStartHandler() {
    // clear raf if trying again
    window.cancelAnimationFrame(rafID);
    
    // set to desired value
    currValue = +this.value;
}

function unlockEndHandler() {
    
    // store current value
    currValue = +this.value;
    
    // determine if we have reached success or not
    if(currValue >= maxValue) {
        successHandler();
    }
    else {
        rafID = window.requestAnimationFrame(animateHandler);
    }
}

// handle range animation
function animateHandler() {
    
    // update input range
    inputRange.value = currValue;
    
    // determine if we need to continue
    if(currValue > -1) {
    	window.requestAnimationFrame(animateHandler);   
    }
    
    // decrement value
    currValue = currValue - speed;
}

// handle successful unlock
function successHandler() {
    console.log('unlocked');
    window.location = 'https://www.google.com';
    
    // reset input range
    inputRange.value = 0;
};

// bind events
inputRange.addEventListener('mousedown', unlockStartHandler, false);
inputRange.addEventListener('mousestart', unlockStartHandler, false);
inputRange.addEventListener('mouseup', unlockEndHandler, false);
inputRange.addEventListener('touchend', unlockEndHandler, false);
       
});
body {
font-family: Helvetica, Arial, sans-serif;
font-weight: 700;
font-size: 1.3vw;
font-color: white;
  
}
.slider-button {
  	position: absolute;
  	top: 50%;
  	left: 50%;
  	transform: translate(-50%, -50%);
 	  width: 21vw;
  	margin: 0 auto;
}
.slider-button p{
  	margin-top: -2.5vw;
    margin-left: 9vw;
    text-transform: uppercase;
}
input[type=range] {
   -webkit-appearance: none !important;
  	width: 100%;
    background: transparent;
}
input[type=range]:focus {
  outline: none;
}
input[type=range]::-webkit-slider-runnable-track {
  width: 21vw;
  height: 3vw;
  cursor: grab;
  background: grey;
  border-radius: 1.4vw;
  border: 0.25vw solid black;
}
input[type=range]::-webkit-slider-thumb {
  border: 0.25vw solid black;
  width: 4.5vw;
  height: 3vw;
  border-radius: 1.1vw;
  background: white;
  background-size: cover;
  cursor: grab;
  -webkit-appearance: none;
  -webkit-animation-name: bounce;
  -webkit-animation-duration: 1.5s;
  -webkit-animation-fill-mode: both;
  -webkit-animation-timing-function: linear;
  -webkit-animation-iteration-count: infinite;
}
input[type=range]::-moz-range-track {
  width: 21vw;
  height: 3.5vw;
  cursor: grab;
  background: grey;
  border-radius: 1.4vw;
  border: 0.25vw solid black;
}
input[type=range]::-moz-range-thumb {
  border: 0.25vw solid black;
  width: 4.5vw;
  height: 3vw;
  border-radius: 1.1vw;
  background: white;
  background-size: cover;
  cursor: grab;
  -moz-appearance: none;
  -moz-animation-name: bounce;
  -moz-animation-duration: 1.5s;
  -moz-animation-fill-mode: both;
  -moz-animation-timing-function: linear;
  -moz-animation-iteration-count: infinite;
}
input[type=range]::-ms-track {
  width: 17vw;
  height: 3vw;
  cursor: pointer;
  background: transparent;
  border-color: transparent;
  color: transparent;
}
input[type=range]::-ms-fill-lower {
  border: 0.25vw solid black;
  border-radius: 2.6px;
}
input[type=range]::-ms-fill-upper {
  border: 0.25vw solid black;
  border-radius: 1.1vw;
}
input[type=range]::-ms-thumb {
  border: 0.25vw solid #C64686;
  width: 4.5vw;
  height: 3vw;
  border-radius: 1.1vw;
  cursor: grab;
}
input[type=range]:focus::-ms-fill-lower {
  background: grey;
}
input[type=range]:focus::-ms-fill-upper {
  background: white;
}
.pullee {
  width: 4.5vw;
  height: 3vw;
}
.pullee:focus {
  outline: none;
}
.pullee::-webkit-slider-thumb {
  appearance: none;
  display: block;
  width: 4.5vw;
  height: 3vw;
  border-radius: 50%;
  background: white;
  background-size: cover;
  transform-origin: 50% 50%;
  transform: scale(1);
  transition: transform ease-out 100ms;
  cursor: -webkit-grab;
  cursor: -moz-grab;
  -webkit-animation-name: bounce;
  -webkit-animation-duration: 1.5s;
  -webkit-animation-fill-mode: both;
  -webkit-animation-timing-function: linear;
  -webkit-animation-iteration-count: infinite;
}
.pullee::-moz-range-thumb {
  border: 0;
  display: block;
  width: 4.5vw;
  height: 3vw;
  border-radius: 50%;
  background: white;
  background-size: cover;
  transform-origin: 50% 50%;
  transform: scale(1);
  transition: transform ease-out 100ms;
  cursor: -webkit-grab;
  cursor: -moz-grab;
  -moz-animation-name: bounce;
  -moz-animation-duration: 1.5s;
  -moz-animation-fill-mode: both;
  -moz-animation-timing-function: linear;
  -moz-animation-iteration-count: infinite;
}
.pullee::-ms-thumb {
  display: block;
  width: 4.5vw;
  height: 3vw;
  border-radius: 50%;
  background: white;
  background-size: cover;
  transform-origin: 50% 50%;
  transform: scale(1);
  transition: transform ease-out 100ms;
  cursor: -webkit-grab;
  cursor: -moz-grab;
  -ms-animation-name: bounce;
  -ms-animation-duration: 1.5s;
  -ms-animation-fill-mode: both;
  -ms-animation-timing-function: linear;
  -ms-animation-iteration-count: infinite;
}
.pullee::-webkit-slider-runnable-track {
  height: 21vw;
  padding: 0.25rem;
  box-sizing: content-box;
  border-radius: 1.4vw;
  border: 0.25vw solid black;
  background-color: grey;
  -webkit-animation: none !important;
}
.pullee::-moz-range-track {
  height: 21vw;
  padding: 0.25rem;
  box-sizing: content-box;
  border-radius: 1.4vw;
  border: 0.25vw solid black;
  background-color: grey;
}
.pullee::-moz-focus-outer {
  border: 0;
}
.pullee::-ms-track {
  border: 0;
  height: 1rem;
  padding: 0.25rem;
  box-sizing: content-box;
  border-radius: 1.4vw;
  border: 0.25vw solid black;
  background-color: grey;
  color: transparent;
  animation: step-end;
}
.pullee::-ms-fill-lower, .pullee::-ms-fill-upper {
  background-color: transparent;
}
.pullee::-ms-tooltip {
  display: none;
}
.animated {
  -webkit-animation-duration: 1.5s;
  animation-duration: 1.5s;
  -webkit-animation-fill-mode: both;
  animation-fill-mode: both;
  -webkit-animation-timing-function: linear;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
  -webkit-animation-iteration-count: infinite;
}

@-webkit-keyframes bounce {
  0%, 10%, 20%, 40%, 70%, 100% {-webkit-transform: translateX(0);}
  50% {-webkit-transform: translateX(1.5vw);}
}

@keyframes bounce {
  0%, 10%, 20%, 40%, 70%, 100% {transform: translateX(0);}
  50% {transform: translateX(1.5vw);}
}

.bounce {
  -webkit-animation-name: bounce;
  animation-name: bounce;
}
.pullee:hover {
    animation: step-end;
    -moz-animation: step-end;
    -webkit-animation: step-end;
    -ms-animation: step-end;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<div class="slider-button">
<input type="range" value="0" class="pullee" />
   <p>Slide to go</p>
</div>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...