Jquery隐藏显示ScrollTop

时间:2013-08-23 13:40:44

标签: javascript jquery html animation mousehover

当我向下滚动时,我正在寻找一种方法来显示我的div的孩子们。

这是我的代码:

$(document).ready(function (e) {

    var test = 0;
    $('#one').children('div').hide().css({
        'overflow': 'hidden'
    });

    $('#one').hover(function () {
        $(this).children('div').stop(true, true).show('slow');
    }, function () {
        $(this).children('div').stop(true, true).hide('slow');
    });

当我向下滚动两次(~30像素)时,我想显示div孩子,所以当用户再次到达他的屏幕顶部时,他可以看到div孩子但是这样:

if ($(window).scrollTop() >11) {
        test+=1;
    }

if(test!==0){
    $('#one').children('div').show().css({
       'overflow': 'visible'
    });

似乎不起作用。我希望这个技巧能够在不修改mousehoverfunction的情况下工作。

here the jsfiddle for better understanding

1 个答案:

答案 0 :(得分:1)

<强> DEMO

试试这个

 $(document).ready(function (e) {
    var test = 0;
    $('#one').children('div').hide().css({
        'overflow': 'hidden'
    });
    $('#one').hover(function () {

        $(this).children('div').stop(true, true).show('slow');
    }, function () {
        $(this).children('div').stop(true, true).hide('slow');
    });

});
$(window).scroll(function(event) {

    if ($(window).scrollTop() >11) {
     $('#one').children('div').stop(true,true).show();
    }

});

希望这有帮助,谢谢

相关问题