<i id='MZ4Ne'><tr id='MZ4Ne'><dt id='MZ4Ne'><q id='MZ4Ne'><span id='MZ4Ne'><b id='MZ4Ne'><form id='MZ4Ne'><ins id='MZ4Ne'></ins><ul id='MZ4Ne'></ul><sub id='MZ4Ne'></sub></form><legend id='MZ4Ne'></legend><bdo id='MZ4Ne'><pre id='MZ4Ne'><center id='MZ4Ne'></center></pre></bdo></b><th id='MZ4Ne'></th></span></q></dt></tr></i><div id='MZ4Ne'><tfoot id='MZ4Ne'></tfoot><dl id='MZ4Ne'><fieldset id='MZ4Ne'></fieldset></dl></div>

  • <small id='MZ4Ne'></small><noframes id='MZ4Ne'>

    1. <tfoot id='MZ4Ne'></tfoot>

        <legend id='MZ4Ne'><style id='MZ4Ne'><dir id='MZ4Ne'><q id='MZ4Ne'></q></dir></style></legend>

          <bdo id='MZ4Ne'></bdo><ul id='MZ4Ne'></ul>
      1. jQuery 图像网格系统

        jQuery image Grid System(jQuery 图像网格系统)

            <small id='JCkD8'></small><noframes id='JCkD8'>

          1. <legend id='JCkD8'><style id='JCkD8'><dir id='JCkD8'><q id='JCkD8'></q></dir></style></legend>
              <tbody id='JCkD8'></tbody>
            • <bdo id='JCkD8'></bdo><ul id='JCkD8'></ul>
              <i id='JCkD8'><tr id='JCkD8'><dt id='JCkD8'><q id='JCkD8'><span id='JCkD8'><b id='JCkD8'><form id='JCkD8'><ins id='JCkD8'></ins><ul id='JCkD8'></ul><sub id='JCkD8'></sub></form><legend id='JCkD8'></legend><bdo id='JCkD8'><pre id='JCkD8'><center id='JCkD8'></center></pre></bdo></b><th id='JCkD8'></th></span></q></dt></tr></i><div id='JCkD8'><tfoot id='JCkD8'></tfoot><dl id='JCkD8'><fieldset id='JCkD8'></fieldset></dl></div>

                <tfoot id='JCkD8'></tfoot>
                  本文介绍了jQuery 图像网格系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个关于图像网格系统的问题.

                  我从 codepen.io 创建了这个

                  I have one question about image grid system.

                  I created this DEMO from codepen.io

                  In this demo you can see :

                  <div class="photo-row">
                  <div class="photo-item">
                  <!--Posted image here <img src="image/abc.jpg"/>-->
                  </div>
                  </div>
                  

                  This DEMO is working fine but. My question is how can I use my grid system like in this css:

                  <div class="photo">
                  
                          <div class="photo-row">
                              <a href="#"><img src="abc.jpg"/></a>
                          </div>
                          <div class="photo-row">
                              <a href="#"><img src="abc.jpg"/></a>
                          </div>
                  </div>
                  

                  I created second demo for this: second DEMO. In the second demo you can see the grid system not working like first DEMO.

                  Also my jQuery code:

                  (function($,sr){
                  
                    var debounce = function (func, threshold, execAsap) {
                        var timeout;
                  
                        return function debounced () {
                            var obj = this, args = arguments;
                            function delayed () {
                                if (!execAsap)
                                    func.apply(obj, args);
                                timeout = null;
                            };
                  
                            if (timeout)
                                clearTimeout(timeout);
                            else if (execAsap)
                                func.apply(obj, args);
                  
                            timeout = setTimeout(delayed, threshold || 100);
                        };
                    }
                    // smartresize 
                    jQuery.fn[sr] = function(fn){  return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr); };
                  
                  })(jQuery,'smartresize');
                  
                  /* Wait for DOM to be ready */
                  $(function() {
                  
                      // Detect resize event
                      $(window).smartresize(function () {
                          // Set photo image size
                          $('.photo-row').each(function () {
                              var $pi    = $(this).find('.photo-item'),
                                    cWidth = $(this).parent('.photo').width();
                  
                              // Generate array containing all image aspect ratios
                              var ratios = $pi.map(function () {
                                  return $(this).find('img').data('org-width') / $(this).find('img').data('org-height');
                              }).get();
                  
                              // Get sum of widths
                              var sumRatios = 0, sumMargins = 0,
                            minRatio  = Math.min.apply(Math, ratios);
                              for (var i = 0; i < $pi.length; i++) {
                                  sumRatios += ratios[i]/minRatio;
                              };
                  
                        $pi.each(function (){
                          sumMargins += parseInt($(this).css('margin-left')) + parseInt($(this).css('margin-right'));
                        });
                  
                              // Calculate dimensions
                              $pi.each(function (i) {
                                  var minWidth = (cWidth - sumMargins)/sumRatios;
                                  $(this).find('img')
                            .height(Math.floor(minWidth/minRatio))
                                      .width(Math.floor(minWidth/minRatio) * ratios[i]);
                              });
                          });
                      });
                  });
                  
                  /* Wait for images to be loaded */
                  $(window).load(function () {
                  
                      // Store original image dimensions
                      $('.photo-item img').each(function () {
                        $(this)
                          .data('org-width', $(this)[0].naturalWidth)
                          .data('org-height', $(this)[0].naturalHeight);
                      });
                  
                    $(window).resize();
                  });
                  

                  Anyone can help me in this regard ? Thank you in advance for your answer.

                  解决方案

                  Since you'll be creating the HTML dynamically you should remove the .photo-row container but keep .photo-item like so:

                          <div class="photo-item">
                              <a href="..."><img src="..." /></a>
                          </div>
                          <div class="photo-item">
                              <a href="..."><img src="..." /></a>
                          </div>
                          <div class="photo-item">
                              <a href="..."><img src="..." /></a>
                          </div>
                          ...
                  

                  Then what you can do is wrap your elements with .photo-row on page load. First starting with various sets of two:

                  var imgGrab  = $('.photo-item'); //photos
                  var imgLength = imgGrab.length; //number of photos
                  
                  for ( i=0; i<imgLength; i=i+3 ) {
                     imgGrab.eq(i+1).add( imgGrab.eq(i+1) ).add( imgGrab.eq(i+2) ).wrapAll('<div class="photo-row"></div>'); //wrap photos
                  }
                  

                  Then find the remanding ones and wrap those with .photo-row as well:

                  $(".photo-item").each(function(){
                     if($(this).parent().is(":not(.photo-row)")){
                       $(this).wrap('<div class="photo-row"></div>');
                     }
                  });
                  

                  This will wrap your images dynamically and let the CSS do its job regardless of the number of them:

                  CODEPEN

                  这篇关于jQuery 图像网格系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  quot;Status Code:200 OK (from ServiceWorker)quot; in Chrome Network DevTools?(“状态码:200 OK(来自 ServiceWorker)在 Chrome 网络开发工具中?)
                  How to set a header for a HTTP GET request, and trigger file download?(如何为 HTTP GET 请求设置标头并触发文件下载?)
                  Adding custom HTTP headers using JavaScript(使用 JavaScript 添加自定义 HTTP 标头)
                  SQL Query DocumentDB in Azure Functions by an integer not working(通过整数在 Azure Functions 中 SQL 查询 DocumentDB 不起作用)
                  Azure Functions [JavaScript / Node.js] - HTTP call, good practices(Azure Functions [JavaScript/Node.js] - HTTP 调用,良好实践)
                  Azure Functions - Import Custom Node Module(Azure Functions - 导入自定义节点模块)

                    <small id='X4p5Y'></small><noframes id='X4p5Y'>

                      <bdo id='X4p5Y'></bdo><ul id='X4p5Y'></ul>

                      <i id='X4p5Y'><tr id='X4p5Y'><dt id='X4p5Y'><q id='X4p5Y'><span id='X4p5Y'><b id='X4p5Y'><form id='X4p5Y'><ins id='X4p5Y'></ins><ul id='X4p5Y'></ul><sub id='X4p5Y'></sub></form><legend id='X4p5Y'></legend><bdo id='X4p5Y'><pre id='X4p5Y'><center id='X4p5Y'></center></pre></bdo></b><th id='X4p5Y'></th></span></q></dt></tr></i><div id='X4p5Y'><tfoot id='X4p5Y'></tfoot><dl id='X4p5Y'><fieldset id='X4p5Y'></fieldset></dl></div>
                          <tbody id='X4p5Y'></tbody>
                        <legend id='X4p5Y'><style id='X4p5Y'><dir id='X4p5Y'><q id='X4p5Y'></q></dir></style></legend>
                        • <tfoot id='X4p5Y'></tfoot>