添加新的DOM元素后,没有处理新元素的路径点只处理旧元素?

时间:2013-06-01 15:34:01

标签: jquery jquery-waypoints

这是我尝试过的,即使我尝试过也没有工作

$(document).ready(function () {
    $('.entry-item').waypoint(function (direction) {
        if (direction === "down") {
            $(this).children(".sticky-items").css({
                "position": "fixed",
                "top": "45px",
                "right": "0px"
            });
        } else if (direction === "up") {
            $(this).children(".sticky-items").removeAttr("style");
        }
    }, {
        offset: 5
    });
    window.addmore = function () {
        var $newdiv1 = $('<div class="entry-item"><div class="sticky-items">STICK XX</div><div>');
    $('#entries').append($newdiv1);
        $.waypoints('refresh');
}
});

$。航点( '刷新') 需要帮助!

http://jsfiddle.net/VxqNa/9/

1 个答案:

答案 0 :(得分:2)

您也应该在动态添加的元素上重新初始化waypoint:

DEMO

var initwaypoint = function (direction) {
        if (direction === "down") {
            $(this).children(".sticky-items").css({
                "position": "fixed",
                "top": "45px",
                "right": "0px"
            });
        } else if (direction === "up") {
            $(this).children(".sticky-items").removeAttr("style");
        }
    };

$(document).ready(function () {
    $('.entry-item').data('waypoint',true).waypoint(initwaypoint, {
        offset: 5
    });
    window.addmore = function () {
        var $newdiv1 = $('<div class="entry-item"><div class="sticky-items">STICK XX</div></div><div><div class="entry-item"><div class="sticky-items">STICK XX</div><div>');
    $('#entries').append($newdiv1);
        $('.entry-item').filter(function(){
            return !$(this).data('waypoint')
        }).data('waypoint',true).waypoint(initwaypoint, {
        offset: 5
    });

}
});
相关问题