问题
I have a div that sits at the bottom of a slideshow that I want to disappear when the user scrolls or uses down arrow then reappears when scrolls back to the top. I am guessing this is incorporating the jquery scroll functionality?
回答1:
<div>
<div class="a">
A
</div>
</div>
$(window).scroll(function() {
if ($(this).scrollTop() > 0) {
$('.a').fadeOut();
} else {
$('.a').fadeIn();
}
});
Sample
回答2:
$(window).scroll(function () {
var Bottom = $(window).height() + $(window).scrollTop() >= $(document).height();
if(Bottom )
{
$('#div').hide();
}
});
回答3:
Try this code
$('window').scrollDown(function(){$(#div).hide()});
$('window').scrollUp(function(){ $(#div).show() });
回答4:
Here is my answer when you want to animate it and start fading it out after couple of seconds. I used opacity because first of all i didn't want to fade it out completely, second, it does not go back and force after many scrolls.
$(window).scroll(function () {
var elem = $('div');
setTimeout(function() {
elem.css({"opacity":"0.2","transition":"2s"});
},4000);
elem.css({"opacity":"1","transition":"1s"});
});
回答5:
i have a pretty answer try this code ;)
<div id="DivID">
</div>
$("#DivID").scrollview({ direction: 'y' });
$("#DivID > .ui-scrollbar").addClass("ui-scrollbar-visible");
回答6:
$.fn.scrollEnd = function(callback, timeout) {
$(this).scroll(function(){
var $this = $(this);
if ($this.data('scrollTimeout')) {
clearTimeout($this.data('scrollTimeout'));
}
$this.data('scrollTimeout', setTimeout(callback,timeout));
});
};
$(window).scroll(function(){
$('.main').fadeOut();
});
$(window).scrollEnd(function(){
$('.main').fadeIn();
}, 700);
That should do the Trick!
来源:https://stackoverflow.com/questions/13250325/show-hide-div-on-scroll