我创建了一个带有网格的日历布局。该布局描绘了14天的时间,因为人们可以租一辆车一天,而早上必须将其归还。
现在,我想使日历向右滚动,以便用户可以看到的不仅仅是即将到来的两周。我不知道该怎么做,因为遇到以下问题:
grid-template-columns: repeat(28, 1fr);
转换为类似年份(730列,视图中仅显示28列)代码
视图
<div class="wrapper">
<div class="gantt">
<div class="gantt__row gantt__row--months">
<div class="gantt__row-first"></div>
<span>1</span><span>2</span><span>3</span>
<span>4</span><span>5</span><span>6</span>
<span>7</span><span>8</span><span>9</span>
<span>10</span><span>11</span><span>12</span>
<span>13</span><span>14</span>
<span>15</span><span>16</span><span>17</span>
<span>18</span><span>19</span><span>20</span>
<span>21</span><span>22</span><span>23</span>
<span>24</span><span>25</span><span>26</span>
<span>27</span><span>28</span>
</div>
<div class="gantt__row gantt__row--lines" data-month="5">
<span></span><span></span><span></span>
<span></span><span></span><span></span>
<span></span><span></span><span></span>
<span></span><span></span><span></span>
<span></span><span></span>
<span></span><span></span><span></span>
<span></span><span></span><span></span>
<span></span><span></span><span></span>
<span></span><span></span><span></span>
<span></span><span></span>
</div>
<div class="gantt__row">
<div class="gantt__row-first">
</div>
<ul class="gantt__row-bars">
<% count = 1 %>
<% (Date.today).upto(Date.today + 13).each.each do |a| %>
<%# count_old = count %>
<% count += 2 %>
<li style="grid-column: <%= count - 2 %>/ <%= count %>; background-color: #2ecaac;"><%= a.strftime("%a %d") %></li>
<% end %>
</ul>
</div>
<!-- rows car categories and their cars-->
<% @car_categories.each do |cat| %>
<div class="gantt__row">
<div class="gantt__row-first car_cat_row">
<%= cat.name %>
</div>
<ul class="gantt__row-bars car_cat_row">
</ul>
</div>
<% color_pick = 0 %>
<% colors = ['#2ecaac', '#ff6252', '#54c6f9' ] %>
<% cat.cars.each do |car| %>
<% if color_pick == 2 %>
<% color_pick = 0 %>
<% else %>
<% color_pick += 1 %>
<% end %>
<div class="gantt__row">
<div class="gantt__row-first">
<%= car.name %>
</div>
<ul class="gantt__row-bars">
<% car.reservations.where(arrival: Date.today..(Date.today+13)).or(car.reservations.where(departure: Date.today..(Date.today+13))).each do |res| %>
<!-- view start and end date in range -->
<% if res.arrival < Date.today %>
<% start = Date.today %>
<% grid_start = (1+ ((start - Date.today).to_i) *2) %>
<% else %>
<% start = res.arrival + 1%>
<% grid_start = (((start - Date.today).to_i) *2) %>
<% end %>
<% if res.departure > (Date.today + 14) %>
<% end_date = Date.today+14 %>
<% grid_end = ((1+ (end_date - Date.today).to_i) *2) %>
<% elsif res.departure == Date.today %>
<% end_date = Date.today -1 %>
<% grid_end = ((1+ (end_date - Date.today).to_i) *2) %>
<% else %>
<% end_date = res.departure %>
<% grid_end = ((1+ (end_date - Date.today).to_i) *2) %>
<% end %>
<%= link_to park_reservation_path(@park, res), remote: true do %>
<li style="grid-column: <%= grid_start %>/ <%= grid_end %>; background-color: <%= colors[color_pick] %>;">
<%= res.reservation_contact.first_name %>
<%= res.reservation_contact.last_name %>
<% end %>
</li>
<% end %>
</ul>
</div>
<% end %>
<% end %>
</div>
js(尝试滚动)
<script>
document.addEventListener("turbolinks:load", function() {
// $(document).ready(function() {
$("gantt").click(function() {
$("gantt").scrollLeft(100);
});
});
</script>
css
@import url("https://fonts.googleapis.com/css?family=Roboto:100,400,700");
body,
html {
font-family: "Roboto", sans-serif;
background-color: #cddade;
height: 100%;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.header {
color: #202125;
margin-bottom: 40px;
h2 {
font-weight: 600;
}
p {
font-weight: 300;
}
}
$red: #ff6252;
.wrapper {
max-width: 1200px;
min-width: 700px;
margin: 0 auto;
// padding: 40px;
}
.gantt {
display: grid;
border: 0;
// border-radius: 12px;
position: relative;
overflow: hidden;
box-sizing: border-box;
box-shadow: 0 75px 125px -57px #7e8f94;
&__row {
display: grid;
grid-template-columns: 150px 1fr;
background-color: #fff;
&:nth-child(odd) {
background-color: #f5f5f5;
.gantt__row-first {
background-color: #f5f5f5;
}
}
&:nth-child(3) {
.gantt__row-bars {
border-top: 0;
}
.gantt__row-first {
border-top: 0;
}
}
&--empty {
background-color: lighten($red, 25%) !important;
z-index: 1;
.gantt__row-first {
border-width: 1px 1px 0 0;
}
}
&--lines {
position: absolute;
height: 100%;
width: 100%;
background-color: transparent;
grid-template-columns: 150px repeat(28, 1fr);
span {
display: block;
border-right: 1px solid rgba(0, 0, 0, 0.1);
&.marker {
background-color: rgba(10, 52, 68, 0.13);
z-index: 2;
}
}
&:after {
grid-row: 1;
grid-column: 0;
background-color: #1688b345;
z-index: 2;
height: 100%;
}
}
&--months {
color: #fff;
background-color: #112D31 !important;
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
grid-template-columns: 150px repeat(28, 1fr);
.gantt__row-first {
border-top: 0 !important;
background-color: #112D31 !important;
}
span {
text-align: center;
font-size: 13px;
align-self: center;
font-weight: bold;
padding: 20px 0;
}
}
&-first {
background-color: #fff;
border-width: 1px 0 0 0;
border-color: rgba(0, 0, 0, 0.1);
border-style: solid;
padding: 15px 0;
font-size: 13px;
font-weight: bold;
text-align: center;
}
&-bars {
list-style: none;
display: grid;
padding: 9px 0;
margin: 0;
grid-template-columns: repeat(28, 1fr);
grid-gap: 8px 0;
border-top: 1px solid rgba(221, 221, 221, 0.8);
li {
font-weight: 500;
text-align: left;
font-size: 14px;
min-height: 15px;
background-color: #55de84;
padding: 5px 12px;
color: #fff;
overflow: hidden;
position: relative;
cursor: pointer;
border-radius: 20px;
a{color: white !important}
&.stripes {
background-image: repeating-linear-gradient(45deg, transparent, transparent 5px, rgba(255,255,255,.1) 5px, rgba(255,255,255,.1) 12px);
}
&:before,
&:after {
content: "";
height: 100%;
top: 0;
z-index: 4;
position: absolute;
background-color: rgba(0, 0, 0, 0.3);
}
&:before {
left: 0;
}
&:after {
right: 0;
}
}
}
}
}
.form-container-calendar {
background-color: white;
// padding: 20px 35px;
padding: 0px 0px;
font-family: 'Cairo', sans-serif;
color: #495352;
input {
background-color: #EFEFEF;
border: none;
}
select {
background-color: #EFEFEF;
border: none;
}
h4 {
color: #102D31;
}
}
.car_cat_row{
background-color: #FFD6D1 !important;
}