在网站开发的过程中,有时候为了做适应所有的终端设备,让图片根据终端的大小而改变。我们可以使用JS来实现。
<!--产品列表--> <section class="yd_wap_news3 w_wap_news2"> <h2> <i> </i> <em> <a href="/qiudong/" title="产品展示">更多</a></em>产品展示</h2> <ul> <li> <a href="/jack/52.html" target="_self"> <img src="/static/upload/image/style/img/5ccfe345549f7.jpg" alt="" class="yl_auto" > <span>测试产品</span></a> </li> <li> <a href="/jack/51.html" target="_self"> <img src="/static/upload/image/style/img/5ccfe345549f7.jpg" alt="" class="yl_auto" > <span>测试产品</span></a> </li> <li> <a href="/jack/50.html" target="_self"> <img src="/static/upload/image/style/img/5ccfe345549f7.jpg" alt="" class="yl_auto" > <span>测试产品</span></a> </li> <li> <a href="/jack/49.html" target="_self"> <img src="/static/upload/image/style/img/5ccfe345549f7.jpg" alt="" class="yl_auto" > <span>测试产品</span></a> </li> <li> <a href="/jack/48.html" target="_self"> <img src="/static/upload/image/style/img/5ccfe345549f7.jpg" alt="" class="yl_auto" > <span>测试产品</span></a> </li> <li> <a href="/jack/47.html" target="_self"> <img src="/static/upload/image/style/img/5ccfe345549f7.jpg" alt="" class="yl_auto" > <span>测试产品</span></a> </li> <li> <a href="/jack/46.html" target="_self"> <img src="/static/upload/image/style/img/5ccfe345549f7.jpg" alt="" class="yl_auto" > <span>测试产品</span></a> </li> <li> <a href="/jack/45.html" target="_self"> <img src="/static/upload/image/style/img/5ccfe345549f7.jpg" alt="" class="yl_auto" > <span>测试产品</span></a> </li> </ul> <!--产品列表-->
比如说这样一组产品列表。
我们给他加这么一段JS,大概意思就是:通过获取yd_wap_news的宽度,然后设置width等于它的0.485,差不多是一半的值,让高度值也等于这个值。然后并将这个值赋给了yl_auto这个类,也就是给了图片。
<script> var all_pm = $(".yd_wap_news3").width(); width = all_pm * 0.485; height = width / 1; w = width.toString(); w = w + "px"; h = height.toString(); h = h + "px"; $(".yl_auto").css("width", w); $(".yl_auto").css("height", h); </script> </section>
醉后我们可以得到:
<!--产品列表--> <section class="yd_wap_news3 w_wap_news2"> <h2> <i> </i> <em> <a href="/qiudong/" title="产品展示">更多</a></em>产品展示</h2> <ul> <li> <a href="/jack/52.html" target="_self"> <img src="/static/upload/image/style/img/5ccfe345549f7.jpg" alt="" class="yl_auto" style="width: 254.14px; height: 254.14px;"> <span>测试产品</span></a> </li> <li> <a href="/jack/51.html" target="_self"> <img src="/static/upload/image/style/img/5ccfe345549f7.jpg" alt="" class="yl_auto" style="width: 254.14px; height: 254.14px;"> <span>测试产品</span></a> </li> <li> <a href="/jack/50.html" target="_self"> <img src="/static/upload/image/style/img/5ccfe345549f7.jpg" alt="" class="yl_auto" style="width: 254.14px; height: 254.14px;"> <span>测试产品</span></a> </li> <li> <a href="/jack/49.html" target="_self"> <img src="/static/upload/image/style/img/5ccfe345549f7.jpg" alt="" class="yl_auto" style="width: 254.14px; height: 254.14px;"> <span>测试产品</span></a> </li> <li> <a href="/jack/48.html" target="_self"> <img src="/static/upload/image/style/img/5ccfe345549f7.jpg" alt="" class="yl_auto" style="width: 254.14px; height: 254.14px;"> <span>测试产品</span></a> </li> <li> <a href="/jack/47.html" target="_self"> <img src="/static/upload/image/style/img/5ccfe345549f7.jpg" alt="" class="yl_auto" style="width: 254.14px; height: 254.14px;"> <span>测试产品</span></a> </li> <li> <a href="/jack/46.html" target="_self"> <img src="/static/upload/image/style/img/5ccfe345549f7.jpg" alt="" class="yl_auto" style="width: 254.14px; height: 254.14px;"> <span>测试产品</span></a> </li> <li> <a href="/jack/45.html" target="_self"> <img src="/static/upload/image/style/img/5ccfe345549f7.jpg" alt="" class="yl_auto" style="width: 254.14px; height: 254.14px;"> <span>测试产品</span></a> </li> </ul> </section> <!--产品列表-->
看到变化了吗?强加了STYLE将给了宽度和高度。
光明网页开发报价第色彩使用的一致性。站颜色的解释仍然很多。选择配色方案时,应手先选择并匹配页面上的背...
盐田手机网站建设多少钱也为广大媒体人提供了素材。报道同城活动的随处可见,这是的媒体资源,如果不利用起...
有时候在网站建设制作过程中,我们需要达到一种效果,就是当网页下滑的时候,让二级菜单或者侧边菜单进行一...
scrollTop:scrollTop属性表示被隐藏在内容区域上方的像素数。元素未滚动时,scrollTop的值为0,如果元素被垂...