简体   繁体   English

页面内容更改时的布局问题

[英]Layout Issue when content changes on page

I'm stuck on a problem here that I've been trying to d/dx. 我一直在尝试d / dx时遇到问题。 I have a layout for an inventory page, and the css is set up to properly to make it display correctly. 我有一个清单页面的布局,并且将CSS设置为正确以使其正确显示。 Let me start off with the html/php code: 让我从html / php代码开始:

<div class='container-fluid second-row'>
        <div class='row' id='truckviewer-content'>
        </div>
        <div id="display">
        <div class='row content' id='content'>
            <div class='col-md-2 col-md-offset-2 page-title hidden-sm hidden-xs'>
                <h1 class='page-title-top'>Inventory</h1>
            </div>
            <div class='col-md-6'>
                <h3 class='page-sub-title'>Pick Your Rig</h3>
                <p>
                    Not only does Lone Mountain Truck Leasing provide a great selection of reliable semi trucks for sale, usually 3-5 years old, we also ensure your satisfaction because we encourage you to drive the truck off the lot for diagnostic evaluations and required inspections.
                </p>
                <p>
                    Our inventory includes fleets of semi trucks for sale, so take a look at just a few samples of our current inventory, and if you find something you like, give us a call toll-free at 866.512.5685, or contact us with the form below.
                </p>
            </div>
        </div>
        <div class='row'>
            <div class='col-md-10 col-md-offset-1'>
                <form class='form-inline center' role='form'>
                    <h3 class='inventory-sub-title'>Filters</h3>
                    <div class='form-group'>
                        <select id='yearFilter' class='filter form-control'>
                            <option value="allY" selected>-- year --</option>
                            <option value="2015">2015</option>
                            <option value="2014">2014</option>
                            <option value="2013">2013</option>
                            <option value="2012">2012</option>
                            <option value="2011">2011</option>
                            <option value="2010">2010</option>
                            <option value="2009">2009</option>
                            <option value="2008">2008</option>
                            <option value="2007">2007</option>
                        </select>
                    </div>
                    <div class='form-group'>
                        <select id='makeFilter' class='filter form-control'>
                            <option value="allM" selected>-- Make --</option>
                            <option value="freightM">Freightliner</option>
                            <option value="intM">International</option>
                            <option value="kenM">Kenworth</option>
                            <option value="mackM">Mack</option>
                            <option value="peteM">Peterbilt</option>
                            <option value="volvoM">Volvo</option>
                        </select>
                    </div>
                    <div class='form-group'>
                        <select  id='engineFilter' class='filter form-control'>
                            <option value="allE" selected>-- Engine --</option>
                            <option value="catE">Caterpillar</option>
                            <option value="cumE">Cummins</option>
                            <option value="detE">Detroit</option>
                            <option value="mackE">Mack</option>
                            <option value="volE">Volvo</option>
                        </select>
                    </div>
                    <div class='form-group'>
                        <select id='transFilter' class='filter form-control'>
                            <option value="allT" selected>-- Transmission --</option>
                            <option value="10T">10 Speed</option>
                            <option value="13T">13 Speed</option>
                            <option value="18T">18 Speed</option>
                            <option value="autoT">Auto</option>
                        </select>
                    </div>
                    <div class='form-group'>
                        <select id='apuFilter' class='filter form-control'>
                            <option value="allA" selected>-- APU --</option>
                            <option value="apuYes">Yes</option>
                            <option value="apuNo">No</option>
                        </select>
                    </div>
                    <a href="" id="showAll">Show All</a>
                </form>
            </div>
        </div>
            <?
                $truckorder = file_get_contents("truckorder.tpl");
                $truckorder = preg_replace('/\s+/', ' ', trim($truckorder));
                $tagname = "truckorder";
                $trucks = parseContent($truckorder, $tagname);
                $trucks = explode("|", $trucks); 
                foreach($trucks as $truck){
                    $truck = preg_replace('/\s+/', ' ', trim($truck));
                    $quickview = file_get_contents("groups/group_$truck/content/quickview.tpl");
                    $quickview = preg_replace('/\s+/', ' ', trim($quickview));              
                    $tagname = "quickfilter";
                    $filter = parseContent($quickview, $tagname);
                    $tagname = "quicktitle";
                    $title = parseContent($quickview, $tagname);
                    $tagname = "quickprice";
                    $price = parseContent($quickview, $tagname);
                    $tagname = "quicklook";
                    $specs = parseContent($quickview, $tagname);
                    $detailview = file_get_contents("groups/group_$truck/content/detailview.tpl");
                    $detailview = preg_replace('/\s+/', ' ', trim($detailview));
                    $tagname = "trucks";
                    $params = parseContent($detailview, $tagname);
                    $param = explode("|", $params);
                    $param1 = $param[0];
                    $param2 = $param[1];
                    $param3 = $param[2];
                    $param4 = $param[3];
                    $instock = getTruckTotals($param2,$param3,$param4);
                ?>
                <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 truck<?=$filter?>">
                    <div class="item ">
                        <p class='truck-img-align'>
                            <img class="truckTip" src="groups/group_<?=$truck?>/photos/quicktruck.png" border="no-border" />
                        </p>
                        <a class='ajax ajax-main' data-price="<?=$price?>" data-title="<?=$title?>" data-stock="<?=$instock?>" data-truck="<?=$truck?>" href="detail/?id=<?=$truck?>"><div class="caption"><h4>Quick Look</h4><?=$specs?></div></a>
                    </div>
                        <h3 class='truck-title'><?=$title?></h3>
                        <h3 class='truck-price'><?=$price?></h3>
                        <p  class='in-stock'><?=$instock?></p>
                        <a class='ajax bottom-link' data-price="<?=$price?>" data-title="<?=$title?>" data-stock="<?=$instock?>" data-truck="<?=$truck?>" href="detail/?id=<?=$truck?>">Click or hover for more details</a>
                </div>
                <?
                }
                ?>
            </div>
    </div>

EDIT: I have changed the javascript up. 编辑:我已经改变了JavaScript了。 I have added a new sorting algorithm that is beginning to solve the problems that I am facing, but the error is now different. 我添加了一个新的排序算法,该算法开始解决我面临的问题,但是现在的错误有所不同。

$(function(){
    sortDisplay();
});

// Image Overlay
$('.item').hover(function() {
    $(this).find('div.caption').stop(false,true).fadeIn(200);
},
function(){
    $(this).find('div.caption').stop(false,true).fadeOut(200);
});
// Filtering
$("#showAll").click(function(){
    sortDisplay();
    $(".truck").addClass("allY allM allE allT allA");
    $("#yearFilter").val("allY");
    $("#makeFilter").val("allM");
    $('#engineFliter').val("allE");
    $('#transFliter').val("allT");
    $('#apuFliter').val("allA");
    $(".truck").show();
    // Update Filters
    $("#yearFilter option").each(function(){
        var thisClass = $(this).val();
        if($('.'+thisClass+':visible').size() < 1 && $(this).val() !=='allY'){
            $(this).attr('disabled','disabled');
        }
        else{
            $(this).removeAttr('disabled');
        }
    });
    $("#makeFilter option").each(function(){
        var thisClass = $(this).val();
        if($('.'+thisClass+':visible').size() < 1 && $(this).val() !=='allM'){
            $(this).attr('disabled','disabled');
        }
        else{
            $(this).removeAttr('disabled');
        }
    });
    $("#engineFilter option").each(function(){
        var thisClass = $(this).val();
        if($('.'+thisClass+':visible').size() < 1 && $(this).val() !=='allE'){
            $(this).attr('disabled','disabled');
        }
        else{
            $(this).removeAttr('disabled');
        }
    });
    $("#transFilter option").each(function(){
        var thisClass = $(this).val();
        if($('.'+thisClass+':visible').size() < 1 && $(this).val() !=='allT'){
            $(this).attr('disabled','disabled');
        }
        else{
            $(this).removeAttr('disabled');
        }
    });
    $("#apuFilter option").each(function(){
        var thisClass = $(this).val();
        if($('.'+thisClass+':visible').size() < 1 && $(this).val() !=='allA'){
            $(this).attr('disabled','disabled');
        }
        else{
            $(this).removeAttr('disabled');
        }
    });
});
$('.filter').change(function(){
    sortDisplay();
    $(".truck").each(function(){
        $(this).removeClass("truck-reset");
    });
    $(".truck").addClass("allY allM allE allT allA");
    var year = $("#yearFilter").val();
    if(year !=='allY'){
        $(".truck").removeClass("allY");
    }   
    var make = $("#makeFilter").val();
    if(make !=='allM'){
        $(".truck").removeClass("allM");
    }   
    var eng = $("#engineFilter").val();
    if(eng !=='allE'){
        $(".truck").removeClass("allE");
    }   
    var trans = $("#transFilter").val();
    if(trans !=='allT'){
        $(".truck").removeClass("allT");
    }   
    var apu = $("#apuFilter").val();
    if(apu !=='allA'){
        $(".truck").removeClass("allA");
    }   
    $(".truck").hide();
    $(".truck").each(function(){
        if($(this).hasClass(year)&&$(this).hasClass(make)&&$(this).hasClass(eng)&&$(this).hasClass(trans)&&$(this).hasClass(apu)){
            $(this).fadeIn();
        }
    });
    //$("#anchor").slideto();
    // Update Filters
    $("#yearFilter option").each(function(){
        var thisClass = $(this).val();
        if($('.'+thisClass+':visible').size() < 1 && $(this).val() !=='allY'){
            $(this).attr('disabled','disabled');
        }
        else{
            $(this).removeAttr('disabled');
        }
    });
    $("#makeFilter option").each(function(){
        var thisClass = $(this).val();
        if($('.'+thisClass+':visible').size() < 1 && $(this).val() !=='allM'){
            $(this).attr('disabled','disabled');
        }
        else{
            $(this).removeAttr('disabled');
        }
    });
    $("#engineFilter option").each(function(){
        var thisClass = $(this).val();
        if($('.'+thisClass+':visible').size() < 1 && $(this).val() !=='allE'){
            $(this).attr('disabled','disabled');
        }
        else{
            $(this).removeAttr('disabled');
        }
    });
    $("#transFilter option").each(function(){
        var thisClass = $(this).val();
        if($('.'+thisClass+':visible').size() < 1 && $(this).val() !=='allT'){
            $(this).attr('disabled','disabled');
        }
        else{
            $(this).removeAttr('disabled');
        }
    });
    $("#apuFilter option").each(function(){
        var thisClass = $(this).val();
        if($('.'+thisClass+':visible').size() < 1 && $(this).val() !=='allA'){
            $(this).attr('disabled','disabled');
        }
        else{
            $(this).removeAttr('disabled');
        }
    });

});
// Check If Filter Exists Else Disable Select Option
$("#yearFilter option").each(function(){
    var thisClass = $(this).val();
    if($('.'+thisClass+'').size() < 1 && $(this).val() !=='allY'){
        $(this).attr('disabled','disabled');    
    }
});
$("#makeFilter option").each(function(){
    var thisClass = $(this).val();
    if($('.'+thisClass+'').size() < 1 && $(this).val() !=='allM'){
        $(this).attr('disabled','disabled');    
    }
});
$("#engineFilter option").each(function(){
    var thisClass = $(this).val();
    if($('.'+thisClass+'').size() < 1 && $(this).val() !=='allE'){
        $(this).attr('disabled','disabled');    
    }
});
$("#transFilter option").each(function(){
    var thisClass = $(this).val();
    if($('.'+thisClass+'').size() < 1 && $(this).val() !=='allT'){
        $(this).attr('disabled','disabled');    
    }
});
$("#apuFilter option").each(function(){
    var thisClass = $(this).val();
    if($('.'+thisClass+'').size() < 1 && $(this).val() !=='allA'){
        $(this).attr('disabled','disabled');    
    }
});
$('.ajax').click(function(e){
    e.preventDefault();
    var truckWindowId = $(this).data('truck');
    var truckWindowTitle = $(this).data('title');
    var truckWindowStock = $(this).data('stock');
    var truckWindowPrice = $(this).data('price');
    var content = {
        id : truckWindowId,
        title : truckWindowTitle,
        stock : truckWindowStock,
        price : truckWindowPrice
    };
    $.ajax({
        url: "../assets/server/inventory/getTruckDetails.php",
        type: "POST",
        data: content,
        dataType: "JSON",
        cache: false,
        success: function(data){
            var images = data.images;
            $('#display').fadeOut(function(){
                $('#content').fadeOut();
                $('#truckviewer-content').html(data.message).fadeIn();
                //shut off the carousel autoscroll feature
                $('.carousel').carousel({
                  interval: false
                });
                //allow for outside the box to be clickable and closer the div on click
                $(document).mouseup(function(e){
                    var container = $(".truckview");
                    if(!container.is(e.target) && container.has(e.target).length === 0){
                        $('.closer').trigger("click");
                    }
                });
            }); 
        }
    });
});
$(function(){
    $("#truckviewer-content").on('click', '.closer', function(e){
        e.preventDefault();
        var viewer = $('#close-button').data('toggle');
        $(viewer).fadeOut(function(){
            $('#content').fadeIn();
            $('#display').fadeIn();
        });
    });
});


function sortDisplay(){
    var count = 0;
    var vizCount = 0;
    if($(window).width() > 1200){
        $(".truck").each(function(){
            $(this).removeClass('view-sort-left');
            $(this).removeClass('view-sort-right');
            if(count <= 3){
                if(count == 0 && $(this).is(':visible')){
                    vizCount++;
                    $(this).addClass('view-sort-left');
                }else if(count == 3 && $(this).is(':visible')){
                    vizCount++;
                    $(this).addClass('view-sort-right');
                }else if($(this).is(":visible")){
                    vizCount++;
                }
            }else if(count > 3){
                if($(this).is(':visible')){
                    if(vizCount%4 === 0){
                        $(this).addClass('view-sort-left');
                        vizCount++;
                    }else if(vizCount%4 === 3){
                        $(this).addClass('view-sort-right');
                        vizCount++;
                    }else{
                        vizCount++;
                    }
                }
            }
            count++;
        });
    }
}

EDIT: What's happening now is that when the second row of items gets checked the objects won't have the sorting classes of .sort-view-left or .sort-view-right appended to them, but they do in the first row. 编辑:现在正在发生的事情是,当检查第二行项目时,对象将不会附加.sort-view-left或.sort-view-right的排序类,但它们会在第一行中进行。 If you need further explanation please comment, and I'll answer. 如果您需要进一步的解释,请发表评论,我会回答。

This is all working properly but I'm sure I'm going to need to tweek it with what I am trying to figure out what to do. 这一切都正常工作,但是我确定我需要根据自己想弄清楚的方法来进行调整。

When the items change display based on the filter that you pick, the css layout doesn't correct itself, that is because of the nth-child selectors used to pick them. 当项目根据您选择的过滤器更改显示时,css布局不会自行更正,这是因为用于选择它们的第n个子选择器。

.truck{
    width: 16%;
    margin-left: 1%;
    margin-right: 1%;
    min-height: 350px;
    margin-top: 25px;
}
.view-sort-left{
    margin-left: 14% !important;
}

.view-sort-right{
    margin-right: 14% !important;
}

.truck-reset:nth-child(4n-1){
    margin-left: 14%;
}

With all that information above given, it is time to get to the point. 有了以上给出的所有信息,就可以了。 What I'm trying to figure out is how do I change it up so that system is smart enough to decide how many objects are being shown on the inventory page, and then calculate a nice css table based on that. 我想找出的是如何对其进行更改,以使系统足够智能,以决定在清单页面上显示多少个对象,然后基于该对象计算出一个不错的CSS表。 I'm almost considering just doing that from the get go. 我几乎要考虑一开始就这样做。 And then also calculate it based on page width as well. 然后还根据页面宽度进行计算。 This might be too big of a problem to post on here. 这可能是一个太大的问题,无法在此处发布。 I'm not sure, i'm still kind of a noob at posts on here. 我不确定,在这里的帖子上我还是有点菜鸟。 if someone has an idea though let me know. 如果有人有主意,尽管让我知道。 If you think I should consolidate and shrink this problem down let me know that as well, and I can fix problems that way. 如果您认为我应该巩固和缩小这个问题,也请让我知道,并且我可以这样解决问题。 I would like to put my brain together with someone on here though so that I can get to the bottom of this problem. 不过,我还是想和其他人一起努力,使我能够深入研究这个问题。 Hope to hear from some people soon! 希望很快能收到一些人的来信!

Figured it out, I needed to consolidate the two loops into just one and use options within the if statement to determine where my classes should go. 弄清楚了,我需要将两个循环合并为一个循环,并在if语句中使用选项来确定我的类应该去哪里。

function sortDisplay(){
    var count = 0;
    var vizCount = 0;
    if($(window).width() > 1200){
        $(".truck").each(function(){
            $(this).removeClass('view-sort-left');
            $(this).removeClass('view-sort-right');     
                if((count == 0 || vizCount%4 == 0) && $(this).is(':visible')){
                        $(this).addClass('view-sort-left');
                        vizCount++;
                }else if((count == 3 || vizCount%4 == 3)&& $(this).is(':visible')){
                        $(this).addClass('view-sort-right');
                        vizCount++;
                }else if($(this).is(":visible")){
                    vizCount++;
                }
            count++;
        });
    }else if($(window).width() <= 1200 && $(window).width() > 992){
        $(".truck").each(function(){
            $(this).removeClass('view-sort-left');
            $(this).removeClass('view-sort-right');     
                if((count == 0 || vizCount%3 == 0) && $(this).is(':visible')){
                        $(this).addClass('view-sort-left');
                        vizCount++;
                }else if((count == 2 || vizCount%3 == 2)&& $(this).is(':visible')){
                        $(this).addClass('view-sort-right');
                        vizCount++;
                }else if($(this).is(":visible")){
                    vizCount++;
                }
            count++;
        }); 
    }else{
        $(".truck").each(function(){
            $(this).removeClass('view-sort-left');
            $(this).removeClass('view-sort-right');
        });
    }
}

$(window).resize(function(){
    sortDisplay();
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM