Как нарисовать схему мест вагона?

Рейтинг: 1Ответов: 1Опубликовано: 31.03.2023

Пытаюсь сделать что-то похожее, на деле фигня какая-то. Даже блок на линии поделить не выходит, ячейки уезжают. Может кто подскажет как подправить? введите сюда описание изображения

 $(document).ready(function(){
            let div;
            let option;
            let finalprice;
            {
                for(let i=1;i<=20;i++){
                    div = document.createElement('div');
                    div.className = "seatPB";
                    div.id=i;
                    div.innerHTML=i;
                    $('#seat1').append(div);
                }
                for(let i=21;i<=40;i++){
                    div = document.createElement('div');
                    div.className = "seatPB";
                    div.id=i;
                    div.innerHTML=i;
                    $('#seat2').append(div);
                }
            }
                $('#seat').width='1360px';
                for(let i=21;i<=35;i++){
                    div = document.createElement('div');
                    div.className = "seatPB";
                    div.id=i;
                    div.innerHTML=i;
                    $('#seat1').append(div);
                }

            $('.seatPB').click(function(event) {
                for(let i=1;i<=140;i++){
                    $('#'+i).removeClass('active');
                }
                $(this).addClass('active');
                i=event.target.id;
                $('#seatform').text('Место: '+i);
                $('#seatsel').empty();
                option = document.createElement('option');
                option.value='Бизнесс';
                option.innerHTML='Бизнесс';
                $('#seatsel').append(option);
                finalprice=$('#price').val()*1;
                $('#priceOUT').text('Цена: '+finalprice+'₽');
                $('#place').val(i);
            });
            $('.seatP').click(function(event) {
                for(let i=1;i<=140;i++){
                    $('#'+i).removeClass('active');
                }
                i=event.target.id;
                $(this).addClass('active');
                $('#seatform').text('Место: '+i);
                $('#seatsel').empty();
                option = document.createElement('option');
                option.value='Эконом';
                option.innerHTML='Эконом';
                $('#seatsel').append(option);
                option = document.createElement('option');
                option.value='Эконом+';
                option.innerHTML='Эконом+';
                $('#seatsel').append(option);
                finalprice=$('#price').val()*1;
                $('#priceOUT').text('Цена: '+finalprice+'₽');
                $('#placephp').val(i);
            });

            $('#seatsel').change(function(){
                if ($('#seatsel').val()=='Эконом'){
                    finalprice=$('#price').val()*1;
                    $('#priceOUT').text('Цена: '+finalprice+'₽');
                }else{
                    finalprice=$('#price').val()*2;
                    $('#priceOUT').text('Цена: '+finalprice+'₽');
                }
            });
        });
#seat{
    border: 1px solid black;
    width: 1200px;
    height: 300px;
    margin-right:auto ;
    margin-left: auto;
    margin-top: 40px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    
}
#seat1{
    border: 1px solid black;
    width: 100%;
    height: 40%;
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;
    justify-content: space-between;
  
}

#seat2{
    border: 1px solid black;
    width: 100%;
    height: 20%;
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;
    justify-content: space-between;
}
.seatP,.seatPB{
    border: 1px solid black;
    width: 22px;
    height: 45px;
    margin: 5px;
    text-align: center;
}
.seatPB{
    background-color: yellow;
    color: black;
}
.seatP{
    background-color: black;
    color: white;
}
.seatP:hover,.seatPB:hover{
    filter: invert(75%);
}
.bar-line__right {
  flex: 1;
  padding:50px;
  border: 1px solid black;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="seat">
                        <div id="seat1">
                        </div>
  
                        <div id="seat2"></div>
                    </div>

Ответы

▲ 1Принят

Отрисуйте в SVG, свяжите с JS и всё. - De.Minov

Первый раз это делал, стало очень интересно. Может быть вам поможет.

<svg width="910" height="150" viewBox="0 0 910 150" fill="none" xmlns="http://www.w3.org/2000/svg">
<g filter="url(#filter0_d_1_164)">
<path d="M10 0.75H900C905.109 0.75 909.25 4.89137 909.25 10V140C909.25 145.109 905.109 149.25 900 149.25H10C4.89137 149.25 0.75 145.109 0.75 140V10C0.75 4.89137 4.89137 0.75 10 0.75Z" stroke="#AAAAAA" stroke-width="1.5" shape-rendering="crispEdges"/>
</g>
<line x1="140.75" x2="140.75" y2="85" stroke="#AAAAAA" stroke-width="1.5"/>
<line x1="140.75" y1="108" x2="140.75" y2="150" stroke="#AAAAAA" stroke-width="1.5"/>
<line x1="220.75" y1="108" x2="220.75" y2="150" stroke="#AAAAAA" stroke-width="1.5"/>
<line x1="300.75" y1="108" x2="300.75" y2="150" stroke="#AAAAAA" stroke-width="1.5"/>
<line x1="380.75" y1="108" x2="380.75" y2="150" stroke="#AAAAAA" stroke-width="1.5"/>
<line x1="460.75" y1="108" x2="460.75" y2="150" stroke="#AAAAAA" stroke-width="1.5"/>
<line x1="540.75" y1="108" x2="540.75" y2="150" stroke="#AAAAAA" stroke-width="1.5"/>
<line x1="620.75" y1="108" x2="620.75" y2="150" stroke="#AAAAAA" stroke-width="1.5"/>
<line x1="700.75" y1="108" x2="700.75" y2="150" stroke="#AAAAAA" stroke-width="1.5"/>
<line x1="780.75" y1="108" x2="780.75" y2="150" stroke="#AAAAAA" stroke-width="1.5"/>
<line x1="860.75" y1="108" x2="860.75" y2="150" stroke="#AAAAAA" stroke-width="1.5"/>
<line x1="220.75" x2="220.75" y2="85" stroke="#AAAAAA" stroke-width="1.5"/>
<line x1="300.75" x2="300.75" y2="86" stroke="#AAAAAA" stroke-width="1.5"/>
<line x1="380.75" x2="380.75" y2="86" stroke="#AAAAAA" stroke-width="1.5"/>
<line x1="460.75" x2="460.75" y2="86" stroke="#AAAAAA" stroke-width="1.5"/>
<line x1="540.75" x2="540.75" y2="86" stroke="#AAAAAA" stroke-width="1.5"/>
<line x1="620.75" x2="620.75" y2="86" stroke="#AAAAAA" stroke-width="1.5"/>
<line x1="700.75" x2="700.75" y2="86" stroke="#AAAAAA" stroke-width="1.5"/>
<line x1="780.75" x2="780.75" y2="86" stroke="#AAAAAA" stroke-width="1.5"/>
<line x1="860.75" x2="860.75" y2="86" stroke="#AAAAAA" stroke-width="1.5"/>
<path d="M875.491 33C875.161 33 874.927 32.784 874.789 32.352L871.459 21.804C871.387 21.576 871.42 21.348 871.558 21.12C871.702 20.892 871.909 20.778 872.179 20.778C872.323 20.778 872.461 20.826 872.593 20.922C872.725 21.012 872.821 21.156 872.881 21.354L875.815 30.696H875.419L878.209 21.444C878.275 21.228 878.386 21.066 878.542 20.958C878.704 20.85 878.869 20.796 879.037 20.796C879.217 20.796 879.391 20.85 879.559 20.958C879.727 21.066 879.841 21.228 879.901 21.444L882.691 30.696H882.295L885.229 21.354C885.295 21.156 885.388 21.015 885.508 20.931C885.634 20.841 885.769 20.796 885.913 20.796C886.177 20.796 886.387 20.898 886.543 21.102C886.699 21.306 886.735 21.54 886.651 21.804L883.321 32.352C883.177 32.784 882.913 33 882.529 33H882.493C882.091 33 881.827 32.784 881.701 32.352L878.803 22.974H879.199L876.283 32.352C876.223 32.568 876.133 32.73 876.013 32.838C875.899 32.946 875.725 33 875.491 33ZM892.24 33C890.866 33 889.849 32.673 889.189 32.019C888.535 31.359 888.208 30.342 888.208 28.968V24.828C888.208 23.442 888.535 22.422 889.189 21.768C889.843 21.108 890.854 20.784 892.222 20.796H894.4C895.528 20.796 896.389 21.03 896.983 21.498C897.577 21.96 897.922 22.692 898.018 23.694C898.054 23.946 898.006 24.138 897.874 24.27C897.742 24.402 897.55 24.468 897.298 24.468C896.842 24.468 896.578 24.216 896.506 23.712C896.446 23.16 896.254 22.788 895.93 22.596C895.612 22.404 895.102 22.308 894.4 22.308H892.222C891.586 22.302 891.085 22.374 890.719 22.524C890.359 22.674 890.101 22.935 889.945 23.307C889.795 23.673 889.72 24.18 889.72 24.828V28.968C889.72 29.61 889.795 30.114 889.945 30.48C890.101 30.846 890.362 31.107 890.728 31.263C891.094 31.413 891.598 31.488 892.24 31.488H894.4C895.102 31.488 895.612 31.392 895.93 31.2C896.254 31.002 896.446 30.63 896.506 30.084C896.578 29.58 896.842 29.328 897.298 29.328C897.55 29.328 897.742 29.394 897.874 29.526C898.006 29.658 898.054 29.85 898.018 30.102C897.922 31.11 897.577 31.845 896.983 32.307C896.389 32.769 895.528 33 894.4 33H892.24Z" fill="#AAAAAA"/>
<path d="M63.491 29C63.161 29 62.927 28.784 62.789 28.352L59.459 17.804C59.387 17.576 59.42 17.348 59.558 17.12C59.702 16.892 59.909 16.778 60.179 16.778C60.323 16.778 60.461 16.826 60.593 16.922C60.725 17.012 60.821 17.156 60.881 17.354L63.815 26.696H63.419L66.209 17.444C66.275 17.228 66.386 17.066 66.542 16.958C66.704 16.85 66.869 16.796 67.037 16.796C67.217 16.796 67.391 16.85 67.559 16.958C67.727 17.066 67.841 17.228 67.901 17.444L70.691 26.696H70.295L73.229 17.354C73.295 17.156 73.388 17.015 73.508 16.931C73.634 16.841 73.769 16.796 73.913 16.796C74.177 16.796 74.387 16.898 74.543 17.102C74.699 17.306 74.735 17.54 74.651 17.804L71.321 28.352C71.177 28.784 70.913 29 70.529 29H70.493C70.091 29 69.827 28.784 69.701 28.352L66.803 18.974H67.199L64.283 28.352C64.223 28.568 64.133 28.73 64.013 28.838C63.899 28.946 63.725 29 63.491 29ZM80.2396 29C78.8656 29 77.8486 28.673 77.1886 28.019C76.5346 27.359 76.2076 26.342 76.2076 24.968V20.828C76.2076 19.442 76.5346 18.422 77.1886 17.768C77.8426 17.108 78.8536 16.784 80.2216 16.796H82.3996C83.5276 16.796 84.3886 17.03 84.9826 17.498C85.5766 17.96 85.9216 18.692 86.0176 19.694C86.0536 19.946 86.0056 20.138 85.8736 20.27C85.7416 20.402 85.5496 20.468 85.2976 20.468C84.8416 20.468 84.5776 20.216 84.5056 19.712C84.4456 19.16 84.2536 18.788 83.9296 18.596C83.6116 18.404 83.1016 18.308 82.3996 18.308H80.2216C79.5856 18.302 79.0846 18.374 78.7186 18.524C78.3586 18.674 78.1006 18.935 77.9446 19.307C77.7946 19.673 77.7196 20.18 77.7196 20.828V24.968C77.7196 25.61 77.7946 26.114 77.9446 26.48C78.1006 26.846 78.3616 27.107 78.7276 27.263C79.0936 27.413 79.5976 27.488 80.2396 27.488H82.3996C83.1016 27.488 83.6116 27.392 83.9296 27.2C84.2536 27.002 84.4456 26.63 84.5056 26.084C84.5776 25.58 84.8416 25.328 85.2976 25.328C85.5496 25.328 85.7416 25.394 85.8736 25.526C86.0056 25.658 86.0536 25.85 86.0176 26.102C85.9216 27.11 85.5766 27.845 84.9826 28.307C84.3886 28.769 83.5276 29 82.3996 29H80.2396Z" fill="#AAAAAA"/>
<path d="M60.0031 114C60.0031 113.448 60.4508 113 61.0031 113H79.0031C79.5554 113 80.0031 113.448 80.0031 114V128C80.0031 130.761 77.7645 133 75.0031 133H65.0031C62.2417 133 60.0031 130.761 60.0031 128V114Z" fill="#AAAAAA"/>
<line x1="60" y1="135.75" x2="80.0187" y2="135.75" stroke="#AAAAAA" stroke-width="2"/>
<path d="M78.0031 114H83.0031C83.5554 114 84.0031 114.448 84.0031 115V119C84.0031 119.552 83.5554 120 83.0031 120H79.0031C78.4508 120 78.0031 119.552 78.0031 119V114Z" stroke="#AAAAAA" stroke-width="2"/>
<line x1="110" y1="14" x2="118" y2="14" stroke="#AAAAAA" stroke-width="2"/>
<path d="M110 16H118V18C118 20.2091 116.209 22 114 22V22C111.791 22 110 20.2091 110 18V16Z" fill="#AAAAAA"/>
<path d="M106 28.6C106 25.5072 108.507 23 111.6 23H116.4C119.493 23 122 25.5072 122 28.6V28.6C122 29.3732 121.373 30 120.6 30H107.4C106.627 30 106 29.3732 106 28.6V28.6Z" fill="#AAAAAA"/>
<rect x="147" y="15" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="226" y="15" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="307" y="16" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="386" y="16" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="466" y="16" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="546" y="16" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="626" y="15" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="706" y="15" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="786" y="15" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="147" y="108" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="226" y="108" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="307" y="108" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="386" y="108" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="466" y="108" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="546" y="108" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="626" y="108" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="706" y="108" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="786" y="108" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="147" y="55" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="226" y="55" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="307" y="56" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="386" y="56" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="466" y="56" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="546" y="56" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="626" y="55" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="706" y="55" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="786" y="55" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="185" y="15" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="264" y="15" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="345" y="16" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="424" y="16" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="504" y="16" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="584" y="16" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="664" y="15" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="744" y="15" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="824" y="15" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="185" y="55" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="184" y="108" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="263" y="108" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="345" y="108" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="424" y="108" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="504" y="108" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="584" y="108" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="664" y="108" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="744" y="108" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="824" y="108" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="264" y="55" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="345" y="56" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="424" y="56" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="504" y="56" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="584" y="56" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="664" y="55" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="744" y="55" width="30" height="30" rx="5" fill="#D9D9D9"/>
<rect x="824" y="55" width="30" height="30" rx="5" fill="#D9D9D9"/>
<defs>
<filter id="filter0_d_1_164" x="0" y="0" width="910" height="150" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
<feFlood flood-opacity="0" result="BackgroundImageFix"/>
<feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" result="hardAlpha"/>
<feOffset/>
<feComposite in2="hardAlpha" operator="out"/>
<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.25 0"/>
<feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow_1_164"/>
<feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow_1_164" result="shape"/>
</filter>
</defs>
</svg>