我正在尝试使用jquery-lightbox在Rails中创建一个照片查看器。你可以在下面的图片中看到它的设计。
单击较小的图像,将选定的图像显示在上面的大空间中。如果您单击大图像,您可以查看所有图像的灯箱幻灯片,其最初上传的分辨率。
到目前为止,我已经完成了所有这些工作,但是我需要灯光盒从当前选定的图像开始,而不是总是从第一个图像开始。我尝试调用changeImage函数(返回TypeError)并更改activeImage属性(什么都不做)。
这是如何做到的呢?
下面是我正在使用的代码,这些代码目前都在我的show.html.erb中:
<a href="<%= @actor.avatar.url(:large) %>" onclick="javascript:setActiveImage();" class="lightbox" title="<%= @actor.name %>" rel="actor"><%= image_tag @actor.avatar.url(:slide), :id => "actor_headshot", :alt => @actor.name %></a>
<% @actor.photos.each do |photo| %>
<a href="<%= photo.photo.url(:large) %>" class="lightbox" rel="actor"></a>
<% end %>
<div id="actor_photos">
<div id="actor_photo_list">
<% @photos.each_with_index.map do |photo, index| %>
<a href="#" onclick="javascript:swapHeadshot('<%= photo.url(:slide) %>', <%= index %>);"><%= image_tag photo.url(:thumb), :class => "actor_photo_list_item" %></a>
<% end %>
</div>
</div>
<script language="JavaScript">
$('.lightbox').lightbox();
var _am = 0;
function swapHeadshot(source, index)
{
$('#actor_headshot').attr('src', source);
_am = index;
}
function setActiveImage()
{
$('.lightbox').lightbox.activeImage = _am; // has no effect
//$('.lightbox').lightbox({activeImage:_am}); // has no effect
//$('.lightbox').lightbox.changeImage(_am); // returns TypeError
}
</script>

发布于 2011-05-10 19:58:17
默认情况下,jQuery Lightbox附带prev/next按钮。您可能想看看这段代码,一个基于其中任何一个的创建函数,因为它们很可能会为您提供一个答案。
在代码中写着:
$('#lightboxImage').attr('src', opts.imageArray[opts.activeImage][0])width(newWidth).height(newHeight);
resizeImageContainer(newWidth, newHeight);我想这就是你要找的密码。
//编辑:犯了与上面的错误相同的错误,只是他已经给出了答案。
发布于 2011-05-10 20:00:43
changeImage听起来像函数的名称,但是您的代码是:
$('.lightbox').lightbox.changeImage =(_am); //tries to change a function variable to a number你确定不应该:
$('.lightbox').lightbox.changeImage(_am); //calls the function passing a variablehttps://stackoverflow.com/questions/5955601
复制相似问题