您如何才能使警报只发生一次?
$.ajax({
url: '//cdnjs.cloudflare.com/ajax/libs/jquery.appear/0.3.3/jquery.appear.js',
dataType: 'script',
cache: true,
success: function() {
$("#footer").appear();
$("body").on("appear", "#footer", function() {
alert('Footer');
});
}
});
答案 0 :(得分:1)
如果您希望处理程序只触发一次,则使用.one()注册事件处理程序
$.ajax({
url: '//cdnjs.cloudflare.com/ajax/libs/jquery.appear/0.3.3/jquery.appear.js',
dataType: 'script',
cache: true,
success: function() {}
}).done(function() {
$("#footer").appear();
$("body").one("appear", "#footer", function() {
alert('Footer');
});
});
div {
height: 1000px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div></div>
<footer id="footer">asdf</footer>