首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

!怎么显示多行排列的图片[Javascript]

2012-09-25 
求助!如何显示多行排列的图片[Javascript]新手求教,用jquery写一排水平图片可以,如何写多行呢? 只能对一个

求助!如何显示多行排列的图片[Javascript]
新手求教,用jquery写一排水平图片可以,如何写多行呢? 只能对一个div块起作用,后面的块就不起作用了,怎么改呢? 谢谢了
js:
$(document).ready(function(){
var $pic = $('#images a');
$pic.hide();
var imgs = $pic.length;
var next;
for (i=0;i<imgs;i++){
next=$pic.eq(i);
next.css({'position': 'absolute', 'left':150+200*i,'top':25 } );
next.show();
}
});
css:
<div id="aa">
<div id='images'>
<a><img src="image/z1.jpg" width=160px height=160px/></a>
<a><img src="image/z2.jpg" width=160px height=160px/></a>
</div>
</div>
<div id="bb">
<div id='images'>
<a><img src="image/x1.jpg" width=160px height=160px/></a>
<a><img src="image/x2.jpg" width=160px height=160px/></a>
</div>
</div>



[解决办法]

HTML code
<script type="text/javascript">$(function(){    $('.images a').css({"float":"left"});    $('.images').each(function(){        var w=0;        $(this).find("a").each(function(){            w+=$(this).width();        })        $(this).css({"width":w}).parent().css({"width":w});    })}); </script>    <div id="aa">        <div class="images">            <a><img src="b/1.jpg" style="width:160px;height:160px"/></a>            <a><img src="b/2.jpg" style="width:160px;height:160px"/></a>            <a><img src="b/4.jpg" style="width:80px;height:160px"/></a>            <a><img src="b/2.jpg" style="width:170px;height:160px"/></a>        </div>    </div>    <div id="bb">        <div class="images">            <a><img src="b/1.jpg" style="width:160px;height:160px"/></a>            <a><img src="b/2.jpg" style="width:160px;height:160px"/></a>            <a><img src="b/3.jpg" style="width:380px;height:160px"/></a>        </div>    </div>    <div id="cc">        <div class="images">            <a><img src="b/1.jpg" style="width:160px;height:160px"/></a>            <a><img src="b/2.jpg" style="width:160px;height:160px"/></a>        </div>    </div> 

热点排行