Closed. This question needs details or clarity。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
                        
                        5年前关闭。
                                                                                            
                
        
我有以下代码:

$(document).ready(function () {
    if ($('.pi-img').height() > 100) {
        $(this).css('top' , '30%');
        console.log('yeah');
    }
});


但这是行不通的。

最佳答案

您需要使用.each()遍历.pi-img元素:

$(document).ready(function () {
    $('.pi-img').each(function() {
        if ($(this).height() > 100) {
            $(this).css('top' , '30%');
            console.log('yeah');
        }
    });
});

关于javascript - 如果高度超过100像素,请更改位置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23474892/

10-15 11:53