PhantomJS scrollPosition 属性用法


发布日期 : 2020-02-21 15:24:18 UTC

访问量: 10 次浏览

PhantomJS scrollPosition 属性

scrollPosition 属性包含了一个对象,表示滚动位置。该对象包含左右和上下滚动位置的值。通过改变左右和上下滚动位置的值,可以改变页面的滚动位置。或者,通过读取该值可以获取页面的滚动位置。

语法

scrollPosition 语法如下所示 :

var wpage = require('webpage').create()
wpage.scrollPosition;

示例

让我们举一个示例来理解如何使用 scrollPosition 属性。

var wpage = require('webpage').create();
wpage.open('http://localhost/tasks/page1.html', function (status) {
console.log(JSON.stringify(wpage.scrollPosition));
wpage.scrollPosition = {
top:500,
left:30
}
console.log(JSON.stringify(wpage.scrollPosition));
phantom.exit();
});

上面的程序生成以下 输出

{"left":0,"top":0}
{"left":30,"top":500}