如何解决如何在alpineJS中隐藏超出引导模式对话框的内容?
在Bootstrap 4.5 / jquery 3.3 / alpinejs 2.2应用程序中,我显示了具有大小限制的图像 并单击图像,然后使用aplineJS方法打开模式对话框
x-on:click="show_hostel_image_modal = true"
并且可以正常打开,但是我不喜欢对话框后面的所有内容都是可见的。 是否有一种方法可以隐藏它,而无需调用bootstrap js方法,就像我从jquery方法中移出一样?
我有:
@if(!empty($currentHostelImage))
<div
x-data="{ show_hostel_image_modal: false,hostelImages: <?php print prepareEncodeArray($hostelImages) ?>,current_image_id:
{{$currentHostelImage->id }},currentImage : {{$currentHostelImage }} } "
class="hostel_images_block_wrapper">
<div
class="modal_editor_container p-2"
x-show="show_hostel_image_modal"
@click.away="show_hostel_image_modal = false"
>
<div
class="modal_editor_title"
>
<h4 class="modal-title p-2">
{!! $viewFuncs->showAppIcon('image') !!}Image view : <span x-html="currentImage.filenameData.image"></span>
<button class="close" type="button" x-on:click="show_hostel_image_modal= false">
<i class="test-device p-2 pl-4 pr-4 m-0"></i>
<span aria-hidden="true">×</span>
</button>
</h4>
</div> <!-- modal_editor_title -->
<div class="modal_editor_fields" :style="'max-height: ' + ( modalHeight() - 20 ) +'px; '">
<div x-show="typeof currentImage.filenameData != 'undefined'">
<img :src="currentImage.filenameData.image_url" class="hostel_dialog_image m-1 p-1"
:class="{ 'hostel_image' : true }"
>
<div class="alert alert-info" role="alert">
{!! $viewFuncs->showAppIcon('info') !!}
<span x-html="currentImage.filenameData.file_info"></span>
</div>
</div> <!-- <div> -->
</div> <!-- modal_editor_fields-->
</div> <!-- <div class="modal_editor_container"> -->
<template x-for="nextHostelImage in hostelImages">
<div class="hostel_view_current_image_wrapper" x-show="current_image_id === nextHostelImage.id ">
<img :src="nextHostelImage.filenameData.image_url" class="hostel_view_current_image"
:alt="nextHostelImage.filenameData.file_info" x-on:click="show_hostel_image_modal = true" data-toggle="tooltip"
data-placement="top" title="Click to view in full size">
</div>
</template>
</div>
@endif
和样式:
.modal_editor_container {
width: 90%;// !important;
top: 20px;
left: 50px;
position: absolute;
z-index: 900;
flex: 1;
flex-direction: column;
justify-items: flex-start;
padding: 0;
margin: 0;// !important;
}
已修改: 我试图按照导航导航菜单中的步骤进行操作。
请您看看https://jsfiddle.net/z83m7fnc/
我只需要注意hostel_images_block_wrapper-这是所有图像块和 模态对话框的modal_editor_container类。
谢谢!
解决方法
您可以将透明背景应用于div.hostel_images_block_wrapper
.hostel_images_block_wrapper {
background-color: rgba(0,0.5);
position: absolute; (could also be fixed)
top: 0;
left: 0;
height: 100vh;
width: 100%;
}
请确保检查此元素及其包含在页面上下文中的元素的z-index。
使用javascript,您可以通过在正文中添加overflow-y: hidden
来阻止页面在模式后面滚动。
在您的div.hostel_images_block_wrapper上添加以下侦听器
@body-scroll="document.body.style.overflowY = open ? 'hidden' : ''"
然后从任何点击甚至更新您的show_hostel_image_modal
属性的元素中,您都可以调度以下自定义事件:
@click="$dispatch('body-scroll',{})"
作为一个补充说明,由于AlpineJS包含的内容非常丰富,因此您不需要对变量名如此具体。例如,show_hostel_image_modal
可以只是show
或open
。您可以通过这种方式清理大量多余的命名,并使标记更整洁。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。