Panos
asked on
How to scroll to middle of page (with jquery)
Hello experts
I 'm using a function to add a new div onclick loading the content with an ajax call.
The problem is that i cant scroll the new div to the middle of the page.
Below my code.
Any help to fix this?
I 'm using a function to add a new div onclick loading the content with an ajax call.
The problem is that i cant scroll the new div to the middle of the page.
Below my code.
Any help to fix this?
// JavaScript Document
$('#adddiv').live('click', function () {
$.ajax({
type: "POST",
url: "thisfunction.cfc?returnformat=json",
data: {
method: 'fgetinstruction'
},
success: function (f) {
var formattedResponse = $.parseJSON(f);
if (jQuery.isArray(formattedResponse) === true) {
var success = formattedResponse[0]['success'];
var content = formattedResponse[0]['content'];
var newid = formattedResponse[0]['newid'];
if (success === true) {
$(content).appendTo(instruc);
$('#' + newid).scrolltocenter();
return false;
}
}
}
}, "json")
});
jQuery.fn.scrolltocenter = function () {
var scrollto = this.offset().top + (this.height() / 2);
this.animate({
scrollTop: scrollto
});
return this;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you
regards
panos
regards
panos
You are welcome - thanks for the points.
ASKER
Thank you for your correction and the great help.
It is working fine