0

我正在构建一个移动 Web 应用程序,并且在其上使用 jquerytools 滑块。

我希望滑块在所有移动设备上显示(以适当的比例),因此图像的宽度为 100%,高度在 css 中为自动。但是,由于所有元素都是浮动的,并且 jquerytools 滑块需要将位置设置为绝对位置,因此包含的 div (#header) 不会拉伸以适应内容。

我正在尝试使用 jquery 来获取 img 的高度并将该高度应用于标题....但是我没有运气。

CSS:

    #header{
    width:100%;
    position:relative;
    z-index: 20;
    /* box-shadow: 0 0 10px white; */
    overflow: auto;
    }

.scrollable {
position:relative;
overflow:hidden;
width: 100%;
height: 100%;
/* box-shadow: 0 0 20px purple; */
/*  height:198px; */
z-index: 20;
overflow: auto;
}


.scrollable .items {
/* this cannot be too large */
width:1000%;
position:absolute;
clear:both;
/* box-shadow: 0 0 30px green; */

}

.items div {
float:left;
width:10%;
height:100%;

}

/* single scrollable item */
.scrollable img {
    /* float:left; */
    width:100%;
   height: auto;
 /*    height:198px; */
}

/* active item */
.scrollable .active {
    border:2px solid #000;
    position:relative;
    cursor:default;
}

HTML

<div id=header><!-- root element for scrollable -->
<div class="scrollable" id="scrollable">

  <!-- root element for the items -->
  <div class="items">


    <div>
      <img src="img/img2.jpg" />
    </div>


    <div>
       <img src="img/img1.jpg" />
    </div>


    <div>
     <img src="img/img3.jpg" />
    </div>

    <div>
     <img src="img/img4.jpg" />
    </div>

    <div>
     <img src="img/img6.jpg" />
    </div>

</div><!-- items -->

</div><!-- scrollable -->

</div><!-- header -->

更新的查询

            <script>
        $(document).ready(function() {
        $("img.scrollable").each(function() {
            $('#header').css("height",$(this).innerHeight());
        });
        });
        </script>
4

1 回答 1

2

签出这个 jquery 函数:http ://api.jquery.com/height/

于 2012-11-13T20:15:41.500 回答