如何用div

时间:2015-06-29 10:39:03

标签: jquery

我正在使用此代码使div获取其子img的宽度:

jQuery(function() {
    $('.NoOne img').load(function() {
        var $this = $(this);
        $this.parent('.NoOne').width($this.width() - 1);
    })
})
<div class="NoOne">
    <img src="Images/KidsEdu.png" />
    <div style="background-color: #660a42; margin-top: -70px; opacity: 0.8; height: 70px; color: white;">
        <p class="Firstp">
            Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the it to five.
        </p>
        <p class="Secondp">View More...</p>
    </div>
</div>
.NoOne {
    float: left;
    margin-left: 4px;
    height: 230px;
}
.NoOne img {
    height: 230px;
}
.Firstp {
    margin: 0 7px 0 7px;
    text-align: justify;
    height: 32px;
    overflow: hidden;
    font-family: Simplified Arabic;
    font-size: 15px;
    line-height: 16px;
    padding-top: 12px;
    letter-spacing: -1px;
}
.Secondp {
    float: right;
    margin: 3px 7px 0 7px;
    font-family: Simplified Arabic;
    font-weight: bold;
    font-size: 14px;
    letter-spacing: -1px;
}

当我将其包含在滑块中时,div NoOne的宽度为0。如何将this.parent('.NoOne')替换为this.('.NoOne')或类似的内容? 感谢。

0 个答案:

没有答案