Próbuję zrobić pokaz slajdów z bootstrapem, abyś mógł przesuwać obrazy. Ale obrazy nie są wyświetlane. Wyświetlany jest tylko następny i poprzedni przycisk. Używam asp.net mvc5pokaz slajdów z bootstrapem
to jest jquery:
$(document).ready(function() {
$myModal = $('#myModal');
$('.row img.img-responsive').on('click', function() { // <-- notice the selector change
var $this = $(this),
src = $this.attr('src'),
html = '<img src="' + src + '" class="img-responsive" />';
//Start
var index = $(this).parent('.row img.img-responsive').index();
var html = '';
html += html;
html += '<div style="height:25px;clear:both;display:block;">';
html += '<a class="controls next" href="' + (index + 2) + '">next »</a>';
html += '<a class="controls previous" href="' + (index) + '">« prev</a>';
html += '</div>';
//End
updateModalBody($myModal, html);
$myModal.modal();
});
$myModal.on('hidden.bs.modal', function() {
updateModalBody($myModal, '');
});
function updateModalBody($modal, html) {
$modal.find('.modal-body').html(html);
$modal.modal('hide');
}
})
$(document).on('click', 'a.controls', function() {
//this is where we add our logic
var index = $(this).attr('href');
var src = $('ul.row li:nth-child(' + index + ') img').attr('src');
$('.modal-body img').attr('src', src);
var newPrevIndex = parseInt(index) - 1;
var newNextIndex = parseInt(newPrevIndex) + 2;
if ($(this).hasClass('previous')) {
$(this).attr('href', newPrevIndex);
$('a.next').attr('href', newNextIndex);
} else {
$(this).attr('href', newNextIndex);
$('a.previous').attr('href', newPrevIndex);
}
var total = $('ul.row li').length + 1;
//hide next button
if (total === newNextIndex) {
$('a.next').hide();
} else {
$('a.next').show()
}
//hide previous button
if (newPrevIndex === 0) {
$('a.previous').hide();
} else {
$('a.previous').show()
}
return false;
});
i to css/html:
<div id="tabs-2">
<div class="row">
@foreach (var item in Model.LolaBikePhotos)
{
@model ContosoUniversity.Models.UserProfile
@*<div class="col-lg-3 col-md-4 col-xs-6 thumb">*@
<div class="col-lg-2 col-md-2 col-sm-3 col-xs-4 img-thumbnail">
@*<a class="thumbnail">*@
<img class="img-responsive" src="/Images/profile/@item.ImagePath" alt="" />
</div>
<div class="modal hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<div class="modal-content">
<div class="modal-body"></div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->
}
</div>
</div>
Dziękuję
muszę zmodyfikować:
html += html;
Ale nie wiem, jak to zmienić.
ten sposób widać to:
Coś jest nie tak z twoim kodem, nie jestem programistą ASP, ale spójrz na dokumentację Bootstrap Carousel i wykonaj jego kroki, aby stworzyć działający przykład: http://getbootstrap.com/javascript/ #carousel – odedta
Jeśli nadal masz problemy, podaj swój * wygenerowany * HTML - znacznik, który powstanie po przetworzeniu kodu asp.net. –
Czy próbowałeś tego: src = "@ Url.Content (string.Format (" ~/Images/Profile/{0} ", item.ImagePath))"? –