$(window).scrollTop()小于$(document).height() - $(window).height()

时间:2016-02-02 12:41:11

标签: jquery ajax asp.net-mvc

我有一个jquery滚动事件

var page = 0;
 $(document).scroll(function () {
    if ($(window).scrollTop() == $(document).height() - $(window).height()) {//ajax feels when mouse scrolls
        page++;
        var parameters = { "page": page };
        $.ajax({
            url: '@Url.Action("Index")',
            data: parameters,
            success: function (data) {//success Case
                $("#ActivityRecords").append(data);
            }

        });
    }
});

我想调用一个调用LINQ take和skip操作符的控制器函数

public ActionResult Index(int? page)
        {
            var skipRecords = (page != null ? page.Value : 0) * recordsPerPage;
            ActivitiesVM[] Activities = Rep.GetAll(recordsPerPage, skipRecords);
            if (Request.IsAjaxRequest())
            {
                return PartialView("_Activities", Activities);
            }
            string IDUsedInaddNewActivity = Rep.GetID();
            ViewData["ID"] = IDUsedInaddNewActivity;
            return View(Activities);
        }

当我调试这一行

 if ($(window).scrollTop() == $(document).height() - $(window).height())

我得到以下

$(document).height() - $(window).height() = 1113-246 = 867

和 $(窗口).scrollTop()= 866.6666896254934

表示调用ajax请求仍为0.333311

如何才能使此条件成为正确

if ($(window).scrollTop() == $(document).height() - $(window).height())

请注意,我使用谷歌浏览器

0 个答案:

没有答案