jQuery高度条件 [英] JQuery height condition

查看:68
本文介绍了jQuery高度条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$(document).ready(function() {
var pic = $(".pic");

// need to remove these in of case img-element has set width and height
$(".pic").each(function() {
    var $this = $(this);
    $this.css({width: 'auto', height: 'auto'});

    var pic_real_width = $this.width();
    var pic_real_height = $this.height();
    if(pic_real_width<100){
    $(".pic").css("display","none");
    }
    });

 });

我需要这样做来检查.pic类的所有图像的高度(它已经这样做了),然后将display:none添加到具有特定大小的那些图像中. (例如,如果img的宽度小于100像素,则不应显示该图片)

I need this to check for the height of all images of the .pic class (it already does this) and then add a display:none to those who have a certain size. (e.g. if an img has under 100px width it should not be displayed)

推荐答案

这应该可以解决问题:

$(document).ready(function() {
    // need to remove these in of case img-element has set width and height
    $(".pic").each(function() {
        var $this = $(this);
        $this.css({width: 'auto', height: 'auto'});

        var pic_real_width = $this.width();
        var pic_real_height = $this.height();
        if(pic_real_width<100){
            $this.css("display","none");
        }
    });
 });

您再次发现引用了集合,而不是具体元素

you ware again referencing the collection and not a concrete element

这篇关于jQuery高度条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆