如何使用phantomJs滚动页面 [英] How to scroll a page with phantomJs
本文介绍了如何使用phantomJs滚动页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想渲染一个仅在用户滚动页面时加载其图像的页面.仅设置page.scrollPosition
无效.我需要一些随时间变化的滚动位置.
I wanna render a page that load its images only when the user scrolls the page. Just setting page.scrollPosition
has no effect. I need something that change the scroll position over time.
推荐答案
不确定这是否是最好的方法,但它是否有效.它评估页面中的脚本,该脚本随时间增加document.body.scrollTop
并在固定时间后创建屏幕截图.
Not sure if this is the best way but it works. It evaluate a script in the page, that increase document.body.scrollTop
over time and make a screenshot after a fixed time.
page.open "http://www.somePage.com", (status) ->
setTimeout(( ->
page.evaluate(->
pos = 0
scroll = ->
pos += 250
window.document.body.scrollTop = pos
setTimeout(scroll, 100)
scroll()
)
setTimeout((->
page.render('bild.png')
phantom.exit()
), 5000)
), 1000)
这篇关于如何使用phantomJs滚动页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文