Answer the question
In order to leave comments, you need to log in
How to adjust the size of the modal window to the image (picture) in yii2?
Hello.
When you click on the image, a modal window "with full image" appears.
I did it like this
<!--модальное окно для изображений -->
<div class="modal fade" id="my-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-body">
</div>
</div>
</div>
</div>
Событие, нажатие на картинку
$('body').on('click', '.image', function (e) {
var modalContainer = $('#my-modal');
var modalBody = modalContainer.find('.modal-body');
modalContainer.modal({show:true});
var url = $(this).attr('src');
$.ajax({
url: 'modalimage',
type: 'GET',
data: 'url='+url,
success: function (data) {
$('.modal-body').html(data);
modalContainer.modal({show:true});
},
error: function(){
alert('Error in modal Image');
}
});
});
Файл, который рендерится в модальное окно
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\Url;
?>
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<div id="success"></div> <!-- For success message -->
<div class="gb-user-form">
<?php $form = ActiveForm::begin(['options' => ['class' => 'modal-form']]); ?>
<?= Html::img(Url::to([$url]), ['class' => 'img-modal']) ?>
<?php ActiveForm::end(); ?>
</div>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question