【发布时间】: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