shortysbest Posted April 12, 2011 Share Posted April 12, 2011 I've got everything working well except for one thing. My website is primarily hash based, so when i am using the $(window).unbind('scroll') it doesn't work for other pages that use this code to load more comments, so I need to rebind the scroll event to window when hash changes, like: $(window).hashchange(function(){ $(window).bind('scroll'); }); However that doesn't work. The code I ended up using for loading comments is: var finished = true; /////////////////// $(function () { $(window).scroll(function () { if ($(window).height() + $(window).scrollTop() >= $(document).height()-135) { loading(); if(finished) { finished = null; if(get('id')) { var id = get('id'); } else { var id = ''; } var f_post_id = $(".stream li:last").attr('id'); if(stream_loaded) { $.ajax({ type: "POST", url: "ajax/load_old_posts.php", data: "id="+id+"&post_id="+f_post_id, cache: false, success: function(data) { var check_data = data.replace(/^\s+|\s+$/g, ''); if(check_data) { $(".stream li:last").after(data); $(".stream li").fadeIn("slow"); } var lpostid = $(".stream li:last").attr('id'); if(last_id==lpostid) { $(window).unbind('scroll'); } finished = true; end_loading(); } }); } }} }); }); Quote Link to comment Share on other sites More sharing options...
markjoe Posted April 12, 2011 Share Posted April 12, 2011 I must say that I have no idea what "hash based" website means. But you shouldn't need to re-bind the other events, just don't wipe them out in the first place. function loadComments(){ ... } // then use: $(window).bind('scroll', loadComments); // and: $(window).unbind('scroll', loadComments); //as you need At least I think this speaks to the issue your having... Quote Link to comment Share on other sites More sharing options...
shortysbest Posted April 12, 2011 Author Share Posted April 12, 2011 Thank you, I got it working how I wanted. And as to what I called a hash based website I mean it uses javascript to load all of the content rather then just regular pages. for instance my website that's hash based the url looks like www.kithell.com#/home rather than something like www.kithell.com/home or www.kithell.com?page=home This way it doesn't have to reload all of the head content, such as the Jquery files, css, other javascript files that are large. Also allows for a lot of nice features other websites cannot have with a regular navigation system. For instance mine has it so you can watch youtube videos and switch through the pages while continuing to watch it without ending it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.