我有以下结构:
<div class="div1">
<div class="div2">
<div class="jcarousel">
<ul>
<li>
<div class="item">ITEM 1</div>div>
</li>
<li>
<div class="item">ITEM n</div>div>
</li>
</ul>
</div>
<a href="#" class="jcarousel-control-prev">‹</a>
<a href="#" class="jcarousel-control-next">›</a>
</div>
</div>
<ul>
除非<div class="jcarousel">
具有固定的高度,否则我无法使其正常工作,但遗嘱中的每个项目都会具有不同的高度,这与我想要的高度相反。我想<div class="jcarousel">
根据<div>
每个内部的高度动态更改其高度<li>
。
忘了说,这可能很重要。该.Jcarousel div
是一个旋转木马,和我有一个next
和prev
控制。本.Jcarousel div
应根据未来里出现在传送带的高度改变其高度。
的CSS
.div1 {
height: auto;
background: none repeat scroll 0% 0% rgb(255, 255, 255);
border-width: medium 1px 1px;
border-style: none solid solid;
border-color: -moz-use-text-color rgb(255, 255, 255) rgb(255, 255, 255);
padding: 20px 20px 0px;
margin-bottom: 50px;
box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.46);
}
.div2 {
margin-top: -50px;
}
.jcarousel {
position: relative;
overflow: hidden;
height: 700px;
margin: 0px -20px;
padding: 0px 20px;
}
.jcarousel ul {
width: 20000em;
position: absolute;
list-style: none outside none;
margin: 0px;
padding: 0px;
}
.jcarousel li {
float: left;
width: 480px;
}
.item {
margin: 0px;
padding: 0px 20px;
height: 100%;
}
在尝试了一些事情之后,我想出了以下解决方案:
我意识到,预先创建一个具有所有高度的数组,<ul><li>
其响应速度足够快,可以正确更新的高度.Jcarousel div
。
JS
<script type="text/javascript">
$(document).ready(function(){
// checking the height of the first element in the <ul>
var count = 0;
var count_max = $(".jcarousel li").length;
var alturas = [];
$(".jcarousel li div.cenario").each(function(){
var height = $(this).height();
alturas.push(height);
});
$(".jcarousel").css('height',alturas[count]);
// changing height when pressing the prev control
$(document).on("click",".jcarousel-control-prev", function(){
if (count == 0) {
} else {
count = count-1;
$(".jcarousel").css('height',alturas[count]);
}
});
// changing height when pressing the next control
$(document).on("click",".jcarousel-control-next", function(){
if (count !== count_max) {
count = count+1;
$(".jcarousel").css('height',alturas[count]);
} else {
// trying to update the counter when reach the last <li> element within the <ul>
count = 0;
$(".jcarousel").css('height',alturas[count]);
}
});
});
</script>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句