【发布时间】:2015-06-17 08:50:31
【问题描述】:
已编辑:
下面的js代码生成一个这样的模态
但有时它会失败。它看起来像这样
所以我想要解决这个问题
这是html结构
<div class="col-sm-4">
<div class="gallery-item shad" style="height : 100px; width:143px;">
<a href="#">
@if(empty($service->image)))
{{HTML::image('image/no-image.png',null,array('style'=>'height : 100px;'))}}
@else
{{HTML::image('image/'.$service->image,null,array('style'=>'height : 100px;'))}}
@endif
</a>
</div>
文件.js
/* copy loaded thumbnails into carousel */
$('.gallery-image img').on('load', function() {
/*this section execute when i reload the page*/
console.log('not working');
}).each(function(i) {
if(this.complete) {
var item = $('<div class="item"></div>');
var itemDiv = $(this).parent();
$(itemDiv.html()).appendTo(item);
item.appendTo('.carousel-inner');
if (i==0){ // set first item active
item.addClass('active');
}
}
});
/* activate the carousel */
$('#modalCarousel').carousel({interval:false});
/* when clicking a thumbnail */
$('.gallery-image').click(function(e){
e.preventDefault();
var idx = $(this).parents().parents().index();
var id = parseInt(idx);
$('#myModal').modal('show'); // show the modal
$('#modalCarousel').carousel(id); // slide carousel to selected
});
此代码在我第一次加载页面时有效,但是当我重新加载页面并单击图像时,此代码不起作用
【问题讨论】:
-
无法理解您想说什么!能改一下吗?
-
我现在更新问题。请看看
-
超级,那么你在哪里设置模态窗口的内容呢?
-
file.js 文件的前几行
-
查看答案!
标签: javascript jquery twitter-bootstrap