(function () { $.fn.extend({ profile: function () { var a = this.children(".profile_right"), b = this.children(".profile_left"), c = a.find(".profile_right_cnt>p"); b.find(".a-anchors").each(function (e, f) { $(this).attr({ "id": function () { return "a" + e } }) }); a.find(".a-anchors").each(function (e, f) { $(this).attr({ "id": function () { return "a" + e + e }, "href": function () { return "#a" + e } }) }); a.find(".profile_right_cnt>p").on("click", function () { $(this).addClass("floatnav_a_cur").siblings().removeClass("floatnav_a_cur") $("html, body").animate({ scrollTop: $($(this).find('a').attr("href")).offset().top + "px" }, { duration: 500, easing: "swing" }); return false; }); $(window).scroll(function () { var d = $(window).scrollTop(); for (i = 0; i < c.length; i++) { if ($("#a" + i).offset().top <= d) { c.removeClass("floatnav_a_cur"); $("#a" + i + i).parent().addClass("floatnav_a_cur") } } }) } }) })();