Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

237
Visualizações
Why do I use javascript to make the marquee effect and it will shake when it is running?

I have some problems with the marquee effect using JavaScript. It should stop in the middle when scrolling, but it can't stop in the middle at present, it will shake effect. How can I fix this?

I have solved the problem for a lot of time by myself, so I came up to ask everyone, thank you

function slideLine(box,stf,delay,speed,h)
 {
  var slideBox = document.getElementById(box);
  var delay = delay||1000,speed = speed||20,h = h||20;
  var tid = null,pause = false;
  var s = function(){tid=setInterval(slide, speed);}
  var slide = function(){
   if(pause) return;
   slideBox.scrollTop += 1;
   if(slideBox.scrollTop%h == 0){
    clearInterval(tid);
    slideBox.appendChild(slideBox.getElementsByTagName(stf)[0]);
    slideBox.scrollTop = 0;
    setTimeout(s, delay);
   }
  }
  slideBox.onmouseover=function(){pause=true;}
  slideBox.onmouseout=function(){pause=false;}
  setTimeout(s, delay);
 }
 slideLine('ann_box','div',2000,25,20);
.ann{
   overflow:hidden;
   height:60px;
   background-color: #ccc;
   text-align:center;
}
<div id="ann_box" class="ann" style="width:868px;">
  <div id="a1" class="ann">HTML</div>
  <div id="a2" class="ann">CSS</div>
  <div id="a3" class="ann">Vue</div>
  <div id="a4" class="ann">javascript</div>
</div>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I guess, you can achieve this this css transform. But it will work , if the last parameter should be the same as the div's height in the slideLine function and control the speed with the fourth parameter.

css

:root {
  --height: 60px; /* Same as last parameter in function */
}
#ann_box {
  min-width: 400px;
  height: var(--height);
  overflow: hidden;
  border: 1px solid rgba(255, 0, 0, 0.4);
}

.ann {
  height: inherit;
  text-align: center;
  line-height: 1; /* new line */
  /* height / 2 - 10px = transform   to define center */
  transform: translateY(calc(var(--height) / 2 - 10px));
}

javascript

slideLine('ann_box', 'div', 2000, 25, 60); // The last parameter should be 60

function slideLine(box, stf, delay, speed, h) {
  var slideBox = document.getElementById(box);
  var delay = delay || 1000,
    speed = speed || 50,
    h = h || 20;
  var tid = null,
    pause = false;
  var s = function() {
    tid = setInterval(slide, speed);
  };
  var slide = function() {
    if (pause) return;
    slideBox.scrollTop += 1;
    if (slideBox.scrollTop % h == 0) {
      clearInterval(tid);
      slideBox.appendChild(slideBox.getElementsByTagName(stf)[0]);
      // slideBox.scrollTop = 0;
      setTimeout(s, delay);
    }
  };
  slideBox.onmouseover = function() {
    pause = true;
  };
  slideBox.onmouseout = function() {
    pause = false;
  };
  setTimeout(s, delay);
}
slideLine('ann_box', 'div', 2000, 10, 60); // The last parameter should be 60
*,
::after,
::before {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  height: 100vh;
  background-color: hsl(201, 27%, 10%);
  color: white;
  display: flex;
  flex-flow: column;
  align-items: center;
  justify-content: center;
}
:root {
  --height: 60px; /* Same as last parameter in function */
}
#ann_box {
  min-width: 400px;
  height: var(--height);
  overflow: hidden;
  border: 1px solid rgba(255, 0, 0, 0.4);
}

.ann {
  height: inherit;
  text-align: center;
  line-height: 1; /* new line */
  /* height / 2 - 10px = transform   to define center */
  transform: translateY(calc(var(--height) / 2 - 10px));
}

/* height 30px = transform 5px */
/* height 40px = transform 10px */
/* height 50px = transform 15px */
/* height 60px = transform 20px */
<div id="ann_box">
  <div id="a1" class="ann">HTML</div>
  <div id="a2" class="ann">CSS</div>
  <div id="a3" class="ann">Vue</div>
  <div id="a4" class="ann">javascript</div>
</div>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda