jquery - Load javascript into div when user scroll position reaches it -
i want make script load div when user reaches it. trying accomplish using jquery, no success. maybe can help. here code:
var scrollfromtop = $("#float_div_id").offset().top; $(document).scroll(function () { if ($(this).scrolltop() > scrollfromtop) { var s = document.createelement('script'); s.setattribute('type', 'text/javascript'); s.src = 'javascript code src want append on scroll'; document.getelementbyid('float_div_id').appendchild(s); } });
in case, $(this).scrolltop()
coming out lesser scrollfromtop
.
change if condition , try again :
if ($(this).scrolltop() + $(window).height() > scrollfromtop)
Comments
Post a Comment