4
4
4eloBek2015-09-30 21:45:12
css
4eloBek, 2015-09-30 21:45:12

Why does the animation slow down and how to fix it?

Made a "bicycle":
> Example on codepen.io

HTML :

<div class="main">
  <div class="circle1"></div>
</div>

css :
html {overflow: hidden}
.main {
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  position: fixed;
  background: #ccc;
  overflow: hidden;
}
.circle1 {
  position: absolute;
  bottom: 1em;
  right: 1em;
  width: 30px;
  height: 30px;
  background: #008dc7;
  border: 1px solid #008dc7;
  border-radius: 50000px;
  cursor: pointer;
}

JS ( Jquery ):
var min_l = Math.min($('.main').height(), $('.main').width());
var max_l = Math.max($('.main').height(), $('.main').width());
var anim_t = max_l/220;
max_l = max_l * Math.sqrt(2) * 1.5;

var indicator = true;

$('.circle1').click(function() {
  if(indicator) {
    indicator = false;
    $('.circle1').css({'transition': anim_t+'s', 'width': max_l, 'height': max_l, 'transform': 'translate('+min_l+'px,'+min_l+'px)'})
  }
  else {
    indicator = true;
    $('.circle1').removeAttr('style');
  }
})


On pure css it would be smoother, but there would be no interactivity (
How to implement this without lags? ))

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ivanq, 2015-09-30
@4eloBek

jsfiddle.net/Ivanq/c9910wj4
???

A
Andrey Chernyshev, 2015-09-30
@delch

First of all, border-radius: 50000px is not correct. Do 50%, the result will be the same. If there are brakes, try enabling hardware acceleration by 3d transformation:

.main {
  transform: translateZ(0)
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question