使用jquery滚动内容高度

时间:2016-11-22 08:54:24

标签: jquery scroll

div的溢出设置为auto。如何使用jQuery获得向上滚动并且现在不可见的div部分的高度。另外,我怎样才能得到div的可见部分的高度。

$(window).scroll(function () {

        // calculate the percentage the user has scrolled down the page
        var scrollwin = $(window).scrollTop();
        var scrollArticle = $('.main').scrollTop();
        var articleheight = $('.main').outerHeight(true);
        var windowWidth = $(window).width();
        if (scrollwin >= $('.main').offset().top) {
            if (scrollwin <= ($('.main').offset().top + articleheight)) {
//I want this percentage to be calculated on current visible portion of div plus above scrolled portion that is not visible. ScrollArticle is giving 0 value. 
                $('.bar-long').css('width', ((scrollArticle + $(window).height()) / articleheight) * 100 + "%");
            } else {
                $('.bar-long').css('width', "100%");
            }
        } else {
            $('.bar-long').css('width',( $(window).height() / articleheight) * 100 + "%");
        }


    });

1 个答案:

答案 0 :(得分:0)

使用元素的 $params = [ 'index' => Constants::INDEX, 'type' => Constants::DOC_TYPE_USERS, 'body' => [ "query"=> [ "bool"=> [ "must"=> [ "terms"=> [ "weapons.id"=>$params['weapons'] ]], ^ | change this "should"=> [ [ "match"=> [ "firstname"=> $params['search_text'] ]], [ "match"=> [ "lastname"=> $params['search_text'] ]] ] ] ] ] ]; 属性;这是从元素的绝对顶部到可见顶部的高度。