Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/419.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 带节点的幻影_Javascript_Jquery_Node.js_Phantomjs - Fatal编程技术网

Javascript 带节点的幻影

Javascript 带节点的幻影,javascript,jquery,node.js,phantomjs,Javascript,Jquery,Node.js,Phantomjs,我正在尝试使用phantomjs和node在网页上截屏。 我有几乎所有的,但我面临的问题是滚动。 我使用了滚动位置,但滚动不正确 phantom.create() .then(instance => { return instance.createPage(); }) .then(page => { _pageInstance = page; return _pageIn

我正在尝试使用phantomjsnode在网页上截屏。 我有几乎所有的,但我面临的问题是滚动。 我使用了滚动位置,但滚动不正确

phantom.create()
       .then(instance => {
            return instance.createPage();
       })
       .then(page => {
            _pageInstance = page;
            return _pageInstance.open('xyz')})
.then(){ () => {

detailPage = _pageInstance.evaluate(function() {
    var pageSettings = {
        scrollToPos: [],
        elementHeight: [],
        offsetLeft: []
    };
    jQuery('li.diff-comment-activity').each(function(index, item) {
        var offsetTop = jQuery('li.diff-comment-activity .detail')[index].offsetTop;
        var elmntHeight = jQuery('li.diff-comment-activity .detail')[index].offsetHeight;
        var offsetLeft = jQuery('li.diff-comment-activity')[index].offsetLeft;
        pageSettings.scrollToPos.push(offsetTop);
        pageSettings.elementHeight.push(elmntHeight);
        pageSettings.offsetLeft.push(offsetLeft);
    });
    return pageSettings;
});
setTimeout(function() {

    console.log('Getting your screen shots...');
    detailPage.then(function(detail) {
        _details = detail;
        _pageInstance.property('viewportSize', {
            width: 1920,
            height: 1040
        });
        _details.scrollToPos.forEach(function(value, index) {
            _pageInstance.property('scrollPosition', {
                top: value
            });
            _pageInstance.property('clipRect', {
                top: 10,
                left: 300,
                width: 1400,
                height: _details.elementHeight[index]
            });
            console.log('value ' + value);
            _pageInstance.render('Image_' + index + '.jpeg', {
                format: 'jpeg',
                quality: '100'
            });
        });
    });
    console.log('Done');

}, 5000);
}
在这里,我使用jquery获取所有元素的偏移顶部,然后使用scrollposition到达该元素,然后使用clip rect获取屏幕截图

但对于一些屏幕截图,页面只是滚动到偏移顶部之外。 *

最有趣的部分是当我只使用phamtomJS运行代码时 很好

*
任何帮助。

在我看来,您的
设置超时
严重错位。它应该包括
evaluate()
或排除
evaluate()。然后()。