jQuery会对视口产生爆炸效果

时间:2015-03-04 14:44:44

标签: jquery

当元素滚动到视口时,我正在尝试使用爆炸效果。我怎么能只在它可见时才爆炸?我想这很容易实现,但我是jQuery的新手,无法找到答案。对不起,如果有人问过

1 个答案:

答案 0 :(得分:3)

我打算让你把它弄清楚。但这是您需要的开始代码。

JSFiddle

$(document).click(function () {
    $("#toggle").toggle("explode");
});
$(document).scroll(function () {
    var top = $(document).scrollTop();
    if (top > 600) $("#toggle").toggle("explode");
    if (top < 600) $('#two').hide();
});
#toggle {
    width: 100px;
    height: 100px;
    background: #ccc;
    position:fixed;
}
body {
    height: 5000px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.11.3/jquery-ui.js"></script>
<p>Click anywhere to toggle the box.</p>
<div id="toggle"></div>

相关问题