简体   繁体   English

在载入HTML页面时,将用于文本动画的JS代码从“单击”变为“自动”?

[英]Turning this JS Code for Text Animation from “on click” to automatic when HTML page loads?

I'm trying to implement this text animation (N.10 from https://speckyboy.com/css-javascript-text-animation-snippets/ ) 我正在尝试实现此文本动画(来自https://speckyboy.com/css-javascript-text-animation-snippets/的 N.10)

so I copied the HTML and the CSS code worked fine. 所以我复制了HTML,然后CSS代码运行正常。 I got rid of the reload button because that needs to go away. 我摆脱了重新加载按钮,因为这需要取消。 I know that I am supposed to copy the js script code into the head section for it to load automatically, however... I don't know how to "rewrite" it so it stops being a click action...and just becomes a "normal" function. 我知道我应该将js脚本代码复制到头部以使其自动加载,但是...我不知道如何“重写”它,因此它不再是单击操作...而变成一个“正常”功能。

$(function() {
  $('.intro').addClass('go');

  $('.reload').click(function() {
    $('.intro').removeClass('go').delay(200).queue(function(next) {
      $('.intro').addClass('go');
      next();
    });

  });
})

(I got this from the link obviously) I'll make sure to use the ".onload" to get it to run when page is loaded. (显然,我是从链接中获得的)我将确保使用“ .onload”使其在页面加载时运行。 it's probably a very easy thing to do but got kind of confused... 这可能是一件很容易的事,但有些困惑……

I'd be very grateful for the help! 我将非常感谢您的帮助! Thank you :) 谢谢 :)

It's the part that is not 不是一部分

$(selector).click(function() {});

In your case, delete the framed block 根据您的情况, 删除带框的块

$(function() {
  $('.intro').addClass('go');
  $('.reload').click(function() { $('.intro').removeClass('go').delay(200).queue(function(next) { $('.intro').addClass('go'); next(); }); }); 
})

If i get you right, you removed the reload button, but that didn't reflect in your js code. 如果我理解正确,则删除了重新加载按钮,但这未反映在您的js代码中。

$(function() {   $('.intro').addClass('go');   $('.intro').removeClass('go').delay(200) .queue(function(next) {       $('.intro').addClass('go'); next();     }); })
What i did here was to remove the click event added to the non existing reload button. 我在这里所做的是删除添加到不存在的重新加载按钮的click事件。 But you will need to tweak the code to remove the go class and cause the delay. 但是您将需要调整代码以删除go类并引起延迟。 Hope it helps. 希望能帮助到你。

remove it from on click on add it to document.ready like this 从上将其删除,然后单击将其添加到document.ready

$(document).ready(function(){
   $('.intro').addClass('go');
   $('.intro').removeClass('go').delay(200).queue(function(next) {
      $('.intro').addClass('go');
      next();
    });

  });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM