- Php – Scroll to top after Ajax content load
- Best Solution
- Related Solutions
- Scrol page to top using php
- Refresh page on scroll to top of page
- Create a «Scroll To Top» Button with HTML, CSS & JavaScript
- Jquery Scroll To Top Tutorial
- Why does the page scroll up when I submit a form?
- Loading entire page sections based on scroll position
- Scroll top function in php code example
- Scroll to top after history.back
- Using scrollTop to show pixels scrolled
- Div scrolls to top after refresh need to stop auto scroll to the top
- HTML | DOM scrollTop Property
- mikeoberdick / scroll_to_top.php
Php – Scroll to top after Ajax content load
Is there anyway that I can make it so the page will automatically scroll to the top after the content has loaded (via Ajax)?
This is the code I have for displaying the content:
$(document).ready(function () < var my_layout = $('#container').layout(); $("a.item_link").click(function () < $("#loader").fadeIn(); feed_url = $(this).attr("href"); $.ajax(< type: "POST", data: "URL=" + feed_url, url: "view.php", success: function (msg) < $("#view-area").html(msg); $("#loader").fadeOut(); >>); return false; >); >);
So after the ‘view-area’ has loaded its content can I make the page auto scroll to the top?
Best Solution
Just use the scroll function
$('html, body').animate(< scrollTop: 0 >, 0); //nice and slow :) $('html, body').animate(< scrollTop: 0 >, 'slow');
Related Solutions
Javascript – How to get jQuery to perform a synchronous, rather than asynchronous, Ajax request
From the jQuery documentation: you specify the asynchronous option to be false to get a synchronous Ajax request. Then your callback can set some data before your mother function proceeds.
Here’s what your code would look like if changed as suggested:
beforecreate: function (node, targetNode, type, to) < jQuery.ajax(< url: 'http://example.com/catalog/create/' + targetNode.id + '?name=' + encode(to.inp[0].value), success: function (result) < if (result.isOk == false) alert(result.message); >, async: false >); >
Javascript – How to manage a redirect request after a jQuery Ajax call
I read this question and implemented the approach that has been stated regarding setting the response HTTP status code to 278 in order to avoid the browser transparently handling the redirects. Even though this worked, I was a little dissatisfied as it is a bit of a hack.
After more digging around, I ditched this approach and used JSON. In this case, all responses to AJAX requests have the status code 200 and the body of the response contains a JSON object that is constructed on the server. The JavaScript on the client can then use the JSON object to decide what it needs to do.
I had a similar problem to yours. I perform an AJAX request that has 2 possible responses: one that redirects the browser to a new page and one that replaces an existing HTML form on the current page with a new one. The jQuery code to do this looks something like:
The JSON object «data» is constructed on the server to have 2 members: data.redirect and data.form . I found this approach to be much better.
Scrol page to top using php
That way you can make AJAX request when scrolling position is of necessary value, and insert returned HTML into the page. Or in your case create a file that will accept a GET request with section number, and render the output of needed section file as its done in most PHP frameworks (see below).
Refresh page on scroll to top of page
I am creating a website in php , in which I want a division to reload by javascript when the user scroll to the top of the page.
Can anyone guide me how to do this with example?
With using something like jQuery you can do it like this;
Note; the .scroll function is firing each pixel you scroll, for browserload you might want to add a timeout for this
You need to watch the scrollTop value. Simple example:
How To Create a Scroll Back To Top Button, This example demonstrates how to create a «scroll to top» button that becomes visible when the user starts to scroll the page.
Create a «Scroll To Top» Button with HTML, CSS & JavaScript
In this video we’re going to create a «Scroll To Top» button using plain HTML, CSS and Duration: 11:00
Jquery Scroll To Top Tutorial
Why does the page scroll up when I submit a form?
I have made the following form. When I select any of the options, the page automatically scrolls up. Any ideas how do I fix it?
The page isn’t scrolling up.
The form is submitting, and the page is reloading.
The new version of the page loads from the top.
As you are submitting the page, it reloads at the top.
First get the scroll position before submitting and submit it with the form :