之前项目中的列表页需要显示缩略图,进而改成9宫格。在此记录下。
css样式:
a, body, center, cite, code, dd, del, div, dl, dt, em, fieldset, figcaption, figure, footer, form, h1, h2, h3, h4, h5, h6, header, hr, html, img, input, label, legend, li, mark, ol, p, section, span, strong, textarea, time, ul, var input{ margin: 0; border: 0; padding: 0; font-style: normal; color: #fff; box-sizing: border-box; -moz-box-sizing:border-box; /* Firefox */ -webkit-box-sizing:border-box; /* Safari */ } ul{ text-decoration: none; list-style-type: none; } .video_list>li{ float: left; width: 33%; font-size: 0; margin-left: 1px; margin-top: 1px; } .video_list>li>img{ width: 100%; object-fit: cover; }
html结构:
<ul class="video_list"> <li><img src="http://img.jspp.cn/headPortrait_1BHE2Q7A35GPbb0f13ac00001a560da1_1497837240529.jpeg?imageView2/1/w/300/h/300/q/75" alt=""></li> <li><img src="http://img.jspp.cn/headPortrait_1BHE2Q7A35GPbb0f13ac00001a560da1_1497837240529.jpeg?imageView2/1/w/300/h/300/q/75" alt=""></li> <li><img src="http://img.jspp.cn/headPortrait_1BHE2Q7A35GPbb0f13ac00001a560da1_1497837240529.jpeg?imageView2/1/w/300/h/300/q/75" alt=""></li> <li><img src="http://img.jspp.cn/headPortrait_1BHE2Q7A35GPbb0f13ac00001a560da1_1497837240529.jpeg?imageView2/1/w/300/h/300/q/75" alt=""></li> <li><img src="http://img.jspp.cn/headPortrait_1BHE2Q7A35GPbb0f13ac00001a560da1_1497837240529.jpeg?imageView2/1/w/300/h/300/q/75" alt=""></li> <li><img src="http://img.jspp.cn/headPortrait_1BHE2Q7A35GPbb0f13ac00001a560da1_1497837240529.jpeg?imageView2/1/w/300/h/300/q/75" alt=""></li> <li><img src="http://img.jspp.cn/headPortrait_1BHE2Q7A35GPbb0f13ac00001a560da1_1497837240529.jpeg?imageView2/1/w/300/h/300/q/75" alt=""></li> <li><img src="http://img.jspp.cn/headPortrait_1BHE2Q7A35GPbb0f13ac00001a560da1_1497837240529.jpeg?imageView2/1/w/300/h/300/q/75" alt=""></li> <li><img src="http://img.jspp.cn/headPortrait_1BHE2Q7A35GPbb0f13ac00001a560da1_1497837240529.jpeg?imageView2/1/w/300/h/300/q/75" alt=""></li> </ul>
仅仅是拿到点击的哪一张图片的下表;为的点击后跳转指定页面;
jquery代码:
$(function () { $('.video_list').on('click','li',function () { alert($(this).index()+1); }) })
仅此记录下来,为了以后可以翻来看看。同时也希望对大家有用。