将缩略图附加到 DIV 时,如何以特定模式定位缩略图?
我正在构建一个包含 150 个缩略图的图库,并使用 jQuery 脚本将图像放入 DIV 中并将它们链接到更大的版本:
function getImageThumb(number) {
return $('<a href="javascript:void(0);" title="Plate ' + number + '" rel="{gallery: \'gal1\', smallimage: \'./Vol4/Small/tafel_' + number + '.jpg\', largeimage: \'./Vol4/Large/tafel_' + number + '.jpg\'}">' +
'<img src="./Vol4/Thumbs/tafel_' + number + '.jpg" alt="Plate ' + number + '" width="100" height="150" border="0" /></a>');}
$(document).ready(function(){
for (var i=450; i<601; i++) {
$(".pane").append(getImageThumb(i));
}
});
我遇到的问题是定位。每个缩略图的大小为 100 像素 x 150 像素,我想按照以下特定顺序将它们排列为 9 个一组:
01 02 03 10 11 12 19 20 21
04 05 06 13 14 15 22 23 24
07 08 09 16 17 18 25 26 27
这个想法是最终的 DIV 大小为 300 像素 x 450 像素,并且一次仅显示 9 个图像的单个块。用户可以向左或向右滚动以查看不同组的 9 个缩略图。但是,当我创建具有这些尺寸的 DIV 并运行脚本时,它只是溢出了底部,我得到了如下排列的三列和 50 行:
01 02 03
04 05 06
07 08 09
10 11 12
13 14 15 and so forth
任何人都可以向我展示一种简单的方法,在我附加图像时将图像定位到正确的模式中到DIV?
I'm building a gallery of 150 thumbnail images and I'm using a jQuery script to place the images into a DIV and link them to larger versions:
function getImageThumb(number) {
return $('<a href="javascript:void(0);" title="Plate ' + number + '" rel="{gallery: \'gal1\', smallimage: \'./Vol4/Small/tafel_' + number + '.jpg\', largeimage: \'./Vol4/Large/tafel_' + number + '.jpg\'}">' +
'<img src="./Vol4/Thumbs/tafel_' + number + '.jpg" alt="Plate ' + number + '" width="100" height="150" border="0" /></a>');}
$(document).ready(function(){
for (var i=450; i<601; i++) {
$(".pane").append(getImageThumb(i));
}
});
The problem I'm having is with positioning. Each thumbnail is 100px by 150px and I want to arrange them in groups of 9 in this particular order:
01 02 03 10 11 12 19 20 21
04 05 06 13 14 15 22 23 24
07 08 09 16 17 18 25 26 27
The idea is that the finished DIV will be 300px by 450px and show only a single block of 9 images at a time. The user can scroll to the left or right to see different groups of 9 thumbnails. But when I create a DIV with those dimensions and run the script, it just overflows the bottom and I get three columns and 50 rows arranged like this:
01 02 03
04 05 06
07 08 09
10 11 12
13 14 15 and so forth
Can anyone show me a simple way to position the images into the correct pattern as I append them to the DIV?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 模 运算符
Use the modulus operator
你可以这样做:
http://jsfiddle.net/gKkW4/
You can do something like this:
http://jsfiddle.net/gKkW4/