使用 Sweetalert2 时,方向键滚动网站

发布于 2025-01-09 01:42:41 字数 2373 浏览 1 评论 0原文

我使用 Sweetalert2 制作了一个弹出警报。我希望能够使用箭头键在接受和拒绝之间进行选择。然而,它也会影响网站本身,它在后台滚动。我添加了代码(左右箭头键也会影响背景)。 滚动条隐藏在网站中,所以我假设它在某种程度上与此有关。

我该怎么做才能让箭头只影响选择?该表仅存在于代码中,以使站点足够宽以便可以在示例中滚动。

    Swal.fire({
    width: '16rem',
  title: 'CALL!',
  text: "Take call?",
  showDenyButton: true,
  showCancelButton: false,
  confirmButtonColor: '#353535',
  denyButtonColor: '#353535',
  confirmButtonText: 'Yes',
  denyButtonText: 'No',
  allowOutsideClick: false,
  keydownListenerCapture:true,
  stopKeydownPropagation:true
})
.swal2-popup .swal2-styled:focus {
    opacity: 1!important;
    background-color: #6D9E18!important;
    color: white!important;
    box-shadow:none!important;
}

.swal2-styled .swal2-confirm:focus {
    opacity: 1!important;
    background-color: #6D9E18!important;
    color: white!important;
    box-shadow:none!important;
}
.swal2-styled.swal2-default-outline:focus{
    opacity: 1!important;
    background-color: #6D9E18!important;
    color: white!important;
    box-shadow:none!important;
}

.swal2-actions:not(.swal2-loading) .swal2-styled:hover{
   opacity: 1!important;
    background-color: #6D9E18!important;
    color: white!important;
    box-shadow:none!important;
}

html, body{
  background-color: #353535;
  color : #FCFCFC;
  font-family: 'Quicksand';
  font-weight : 700;
  font-size : 4.5vh;
  border-width: 0px;
  border: none;
  height: 100%;
  width: 100%;
  box-sizing: border-box;
  padding: 0px;
  -ms-overflow-style: none; /* for Internet Explorer, Edge */
  scrollbar-width: none; /* for Firefox */
  overflow-y: scroll; 
}

body::-webkit-scrollbar {
    display: none; /* for Chrome, Safari, and Opera */
}
    <script
  src="https://code.jquery.com/jquery-3.6.0.min.js"
  integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
  crossorigin="anonymous"></script>
 <script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script>
 
 <table width="2000px">
 <tr>
   <td>djwaodjsakdjlsakdjsalkdjsalkdjalksfhuebgnmsdvbmncxbvmcxbvhkbmdnbvmnxcbvmnxcbvmncxbvmnxcbvnmcxbvkjadbvdbvhsdbvkdsvbhds</td>
 </tr>
 </table>

I made a popup alert using Sweetalert2. I want to be able to use the arrowkeys to choose between accept and deny. However, it also affects the site itself, it's scrolling in the background. I added the code (right and left arrow keys affect the background too).
The scrollbars are hidden in the site, so I am assuming it has to do with that in some way.

What can I do so the arrows only affect the choice? The table is only there in the code to get the site wide enough to be scrollable for the example.

    Swal.fire({
    width: '16rem',
  title: 'CALL!',
  text: "Take call?",
  showDenyButton: true,
  showCancelButton: false,
  confirmButtonColor: '#353535',
  denyButtonColor: '#353535',
  confirmButtonText: 'Yes',
  denyButtonText: 'No',
  allowOutsideClick: false,
  keydownListenerCapture:true,
  stopKeydownPropagation:true
})
.swal2-popup .swal2-styled:focus {
    opacity: 1!important;
    background-color: #6D9E18!important;
    color: white!important;
    box-shadow:none!important;
}

.swal2-styled .swal2-confirm:focus {
    opacity: 1!important;
    background-color: #6D9E18!important;
    color: white!important;
    box-shadow:none!important;
}
.swal2-styled.swal2-default-outline:focus{
    opacity: 1!important;
    background-color: #6D9E18!important;
    color: white!important;
    box-shadow:none!important;
}

.swal2-actions:not(.swal2-loading) .swal2-styled:hover{
   opacity: 1!important;
    background-color: #6D9E18!important;
    color: white!important;
    box-shadow:none!important;
}

html, body{
  background-color: #353535;
  color : #FCFCFC;
  font-family: 'Quicksand';
  font-weight : 700;
  font-size : 4.5vh;
  border-width: 0px;
  border: none;
  height: 100%;
  width: 100%;
  box-sizing: border-box;
  padding: 0px;
  -ms-overflow-style: none; /* for Internet Explorer, Edge */
  scrollbar-width: none; /* for Firefox */
  overflow-y: scroll; 
}

body::-webkit-scrollbar {
    display: none; /* for Chrome, Safari, and Opera */
}
    <script
  src="https://code.jquery.com/jquery-3.6.0.min.js"
  integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
  crossorigin="anonymous"></script>
 <script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script>
 
 <table width="2000px">
 <tr>
   <td>djwaodjsakdjlsakdjsalkdjsalkdjalksfhuebgnmsdvbmncxbvmcxbvhkbmdnbvmnxcbvmnxcbvmncxbvmnxcbvnmcxbvkjadbvdbvhsdbvkdsvbhds</td>
 </tr>
 </table>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨巷深深 2025-01-16 01:42:41

通过将 html, body { 替换为 body { 来取消设置 html 中的样式

Unset styles from html by replacing html, body { with body {

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文