Casperjs visible()返回true,而jquery是(':visible')为同一个选择器返回false

时间:2015-06-15 05:40:44

标签: javascript visibility casperjs

casper.visible('#percent_med_pickup');返回true,而具有相同选择器的以下代码返回false:

casper.evaluate(function(){

return $('#percent_med_pickup').is(':visible');
});

不是都一样吗?

1 个答案:

答案 0 :(得分:2)

是的,他们非常不同。

CasperJS(source):

this.elementVisible = function elementVisible(elem) {
    var style;
    try {
        style = window.getComputedStyle(elem, null);
    } catch (e) {
        return false;
    }
    var hidden = style.visibility === 'hidden' || style.display === 'none';
    if (hidden) {
        return false;
    }
    if (style.display === "inline" || style.display === "inline-block") {
        return true;
    }
    return elem.clientHeight > 0 && elem.clientWidth > 0;
};

jQuery(source):

jQuery.expr.filters.hidden = function( elem ) {
    // Support: Opera <= 12.12
    // Opera reports offsetWidths and offsetHeights less than zero on some elements
    return elem.offsetWidth <= 0 && elem.offsetHeight <= 0;
};
jQuery.expr.filters.visible = function( elem ) {
    return !jQuery.expr.filters.hidden( elem );
};