【问题标题】:HTML, JS - after clicking the button: wait 5 seconds, add css class, run linkHTML, JS - 点击按钮后:等待 5 秒,添加 css 类,运行链接
【发布时间】:2018-02-28 01:08:16
【问题描述】:

我想要一个按钮,点击后会将css类添加到其他div,等待5秒然后运行链接。

我想要addclass 而不是$(this).animate,但它不起作用

$(function() {

  $('div').click(function(e) {

    e.preventDefault();
    var goTo = this.getAttribute("href");

    // ACTION END
    $(this).animate({
      marginLeft: 300
    }, 3000);
    // ACTION START

    setTimeout(function() {
      window.location = goTo;
    }, 3000);

  });

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='btn1' href="slider.html">
  <div id="btn1-in">Go Stack!</div>
  <div id="btn1-in2">Go Stack!</div>
</div>

【问题讨论】:

  • 你的问题到底是什么?
  • $(this).addClass('aClassName')?
  • 而不是 "$(this).animate({marginLeft:300},3000);"我想要 addClass 但它不起作用
  • 什么不起作用?
  • 我想添加类而不是单击的 div,但例如它包含的 div

标签: javascript jquery html animation hyperlink


【解决方案1】:

而不是 $(this).animate 我想要 addclass 但它不起作用

试试这个:

setTimeout(function() 
{$(this).addClass("AddNewClass") },5000);

【讨论】:

    猜你喜欢
    • 2011-08-11
    • 1970-01-01
    • 2013-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多