我试图阻止使用JQuery e.preventDefault();
滚动,但什么都没有发生,我需要的是停止滚动,当动画DIV走在了屏幕的右侧,滚动必须工作:防止滚动 - JQuery的
$(document).ready(function() {
$(window).on('scroll', function (e) {
var animation = $(".my-container .animation"),
windowScroll = $(window).scrollTop();
if (parseInt(animation.css('left')) + animation.width() < $(window).width()) {
e.preventDefault();
animation.css('left', windowScroll * 1.5);
}
else {
// enable scroll
}
});
})
.my-container{
width:100%;
height:620px;
position:relative;
overflow:hidden;
background-color:#333333;
}
.my-container .animation{
position:absolute;
width:420px;
height:200px;
bottom:0;
left:0;
background-color:#02f15f;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<section class="my-container">
<div class="animation"></div>
</section>
请运行在全屏
它不是重复的,请在我看到这个问题之前! –
我不知道你为什么决定这个问题是重复的?有一个区别,我想防止滚动然后运行它取决于一些条件。 –