everytime when you click the button you set the scrollPos to 0 in your code. As you set scrollPos to scrollTop of body which is always 0. Instead document.body.scrollTop this use scrollTop of particular pacific div according to div ID of class.
Solution 1 :
Problem :
I am using html2canvas for screenshot and append the image. Those things working fine, but After doing that always scroll to top of the page. I need to scroll pacific div according to div id or class. Here is the code that I using:
html2canvas($('#preview_front'), {
onrendered: function (canvas) {
document.getElementById("image_reply").appendChild(canvas);
$('#img_front').val(canvas.toDataURL("image/png"));
var canvas = $('canvas');
canvas.addClass('front_canvas');
}
});
Try with Following code:
var scrollPos;
document.querySelector("screenshotButton").addEventListener("click", function () {
scrollPos = document.body.scrollTop;
html2canvas(document.body, {
onrendered: function (canvas) {
document.body.appendChild(canvas);
window.scrollTo(0, scrollPos);
}
});
});
That is not working for me.