好的,所以我正在制作电梯模拟器。一切的业务逻辑都很好,我正在使用队列。我遇到的问题是将电梯从队列中的一层移动到下一层。我正在使用 HTML、CSS 和 JavaScript/Jquery。到目前为止,我一直在尝试的两种方法是 Jquery 的动画方法和 CSS 翻译。我还没有找到一个像样的答案。我最近的尝试与在 DOM 中使用不可见元素有关,以便获得将电梯移动到的坐标。我将提供代码片段以进行进一步解释。
那是网页的图片,如您所见,我需要能够在任何给定时间将电梯移动到任何给定楼层。
// Called when user selects the Start button
$('#btn-start').click(function() {
// Start the Simulation
let destination = $('#second-floor').offset();
$("#elevator").animate( {right: destination.left, bottom: destination.top}, 4000, "linear", function(){console.log("Elevator finished moving")} );
//});
});
.elevator-visual {
width: 55%;
}
.elevator {
position: relative;
max-width: 10vw;
margin-left: 6vw;
}
.floor {
position: relative;
}
.hidden-destination {
position: absolute;
bottom: 10vw;
left: 11vw;
background: none;
height: 5px;
width: 5px;
}
.floor-bound {
width: 75%;
margin-bottom: 15vw;
}
#first-floor,
#second-floor {
margin-bottom: 0;
}
.floor-title {
margin: 0;
padding: 0;
text-align: right;
color: #777;
margin-right: 6vw;
}
#floor-four-lable {
margin-top: 15vw;
}
.btn-start{
position: static;
border: none;
padding: 8px 21px;
vertical-align: middle;
text-align: center;
cursor: pointer;
border-radius: 5%;
font-size: 24px;
background-color: #b77110;
color: white;
margin-left: 15px;
margin-top: 10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Elevator Diagram -->
<div class="elevator-visual">
<div class="floor">
<div class="hidden-destination"></div>
<p id="floor-four-lable" class="floor-title">Floor 4</p>
<hr id="forth-floor" class="floor-bound" />
</div>
<div class="floor">
<div class="hidden-destination"></div>
<p class="floor-title">Floor 3</p>
<hr id="third-floor" class="floor-bound" />
</div>
<div class="floor">
<div class="hidden-destination"></div>
<p class="floor-title">Floor 2</p>
<hr id="second-floor" class="floor-bound" />
</div>
</div>
侃侃无极
阿晨1998
相关分类