要解决这个问题,你可以使用JavaScript来控制“查看更多”按钮的行为。下面是一个示例代码,展示了如何通过添加事件监听器来阻止模态对话框的显示。
HTML:
CSS:
.modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0, 0, 0, 0.5);
}
.modal-content {
background-color: white;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
}
.close {
color: #aaaaaa;
float: right;
font-size: 28px;
font-weight: bold;
cursor: pointer;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
JavaScript:
const viewMoreBtn = document.getElementById('view-more-btn');
const modal = document.getElementById('modal');
const closeBtn = document.getElementsByClassName('close')[0];
viewMoreBtn.addEventListener('click', function() {
modal.style.display = 'block';
});
closeBtn.addEventListener('click', function() {
modal.style.display = 'none';
});
window.addEventListener('click', function(event) {
if (event.target == modal) {
modal.style.display = 'none';
}
});
在上面的代码中,我们首先获取了按钮、模态对话框和关闭按钮的引用。然后,我们分别为按钮和关闭按钮添加了点击事件监听器,以便在点击按钮时显示模态对话框,点击关闭按钮或模态对话框的其他区域时隐藏模态对话框。最后,我们通过CSS来定义了模态对话框的样式。
希望这可以帮助到你!