- Today
- Total
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
- 재능이의 돈버는 일기
- StresslessLife
- K_JIN2SM
- 소소한 일상
- My Life Style & Memory a Box
- Blog's generation
- 공감 스토리
- 취객의 프로그래밍 연구실
- Love Me
- Dream Archive
- 세상에 발자취를 남기다 by kongmingu
- hanglesoul
- 카마의 IT 초행길
- 느리게.
- 미친듯이 즐겨보자..
- Joo studio
- Gonna be insane
- 악 다 날아갔어!! 갇대밋! 왓더...
- xopowo05
- 맑은공기희망운동
- 엔지니어 독립운동
- 혁준 블로그
- Simple in Complex with Simple
- 무의식이 의식을 지배한다
드럼치는 프로그래머
[JavaScript] On render in Html2Canvas, the page is scrolled to the top 본문
[JavaScript] On render in Html2Canvas, the page is scrolled to the top
드럼치는한동이 2017. 4. 4. 11:10I am using the html2canvas library, using the following code:
html2canvas(document.body, {
onrendered: function(canvas) {
document.body.appendChild(canvas);
}
});
When onrendered
is fired, the page is automatically scrolled to the top. Is there anyway we can maintain our scroll position and not be automatically taken to the top of the page?
Answer
I took a look into the html2canvas.js and saw the following line:
_html2canvas.Parse = function (images, options) {
window.scroll(0,0);
After commenting window.scroll(0,0)
out, it worked fine for me on my local testing. Seems like that behaviour was intended by the author.
Of course you could also save your current scroll position into a variable when firing the code. The way you may do it depends on how you execute html2canvas. If it's a button like on the demo page, you would add an event listener to that button:
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);
}
});
});
[출처] http://stackoverflow.com/questions/18935518/on-render-in-html2canvas-the-page-is-scrolled-to-the-top
'★─Programing > ☆─WebProgram' 카테고리의 다른 글
[JavaScript] 현재 실행중이 URL정보 (0) | 2017.04.04 |
---|---|
[JavaScript] 날짜 및 시간 설정, 경과 시간 계산, 비교 (0) | 2017.04.04 |
[jQuery] 테이블 행 추가/삭제 (0) | 2017.03.21 |
[jQuery] 자주 쓰이는 유용한 팁 (0) | 2017.03.21 |
[JavaScript] 새창으로 form을 submit 하기(새창으로 폼을 서브밋하기) (0) | 2017.03.21 |