【发布时间】:2011-09-27 16:02:45
【问题描述】:
我环顾四周,但没有找到我要找的东西。
基本上,我在使用 jquery 灯箱的页面上有一张图片,以使其更大且更易于查看。除此之外,在原始灯箱处于活动状态的情况下,我现在需要该图像上的“热点”,当鼠标悬停时生成工具提示,或者在单击时生成单独的相对定位的灯箱。
如果您单击自行车并转到产品页面,可以在 Create Bikes 网站上看到我所追求的外观类型。
一直在玩,但我一生都无法解决 - 有没有人知道这是否可能或能够将我指向已经实施了类似功能的任何网站的方向?
编辑:
好的,按照建议,我在这里放了一些现有的代码,希望对您有所帮助。
此代码块是灯箱与调用脚本的类 lightbox-image 一起使用的典型情况。使用的灯箱是 Colorbox。
<p>
<a href="images/search-wheel-big.png" title="This is where the title goes"class="lightboxElement lightbox-image" rel="lightbox-image">
<img class="c-right" alt="alt tag here" src="testimonials_files/SearchWheel.png">
</a>
Some text here
</p>
加载灯箱时,随后出现的
<div id="lightboxContent" style="float: left; width: 500px; height: 554px;">
<div id="lightboxLoadedContent" style="display: block; width: 500px; overflow: auto; height: 507px;">
<img class="lightboxPhoto" src="images/search-wheel-big.png" style="float: none;">
</div>
<div id="lightboxLoadingOverlay" class="" style="height: 554px; display: none;"></div>
<div id="lightboxLoadingGraphic" class="" style="height: 554px; display: none;"></div>
<div id="lightboxTitle" class="" style="display: block;">This is where the title goes</div>
<div id="lightboxCurrent" class="" style="display: none;"></div>
<div id="lightboxNext" class="" style="display: none;"></div>
<div id="lightboxPrevious" class="" style="display: none;"></div>
<div id="lightboxSlideshow" class="" style="display: none;"></div>
<div id="lightboxClose" class="" style="">close</div>
</div>
然后我认为我可以只输入一个 jquery 命令,如下所示:
$(".lightboxPhoto").each(function(){
$(this).append("<div class='hotspot'></div>");
});
我希望我可以多次执行此操作(对于图像上的不同“热点”,可以依次单击/悬停以获取更多信息)并在每个 <div> 标签中插入一个相对定位的背景图像。
但是,代码中没有发生任何事情,这可能与<div> 标签本身是由.js 文件而不是在我的原始html 中生成的事实有关吗?我需要自己编辑 .js 文件吗?
编辑 2 - 解决方案!
大家好!
所以我只是想我会在这里添加我最后所做的事情,以防其他人想要创建相同的效果。
按照 Chris 的建议,我使用了适用于彩盒灯箱的内联命令。不过,我没有使用工具提示,而是从创建自行车网站(参见他们的产品页面之一)中获取了一个想法,并输入了以下 html 代码:
<div style="display:none">
<div class="example1">
<div class="example2">This is where the title goes</div>
<div class="example3">
<span class="example4"></span>
<div class="example5">
<h5 class="example6">Header text here</h5>
<p class="example7">Some more text here</p>
</div>
</div>
</div>
</div>
<span> 标记和 <div> 标记为 example5 都有一个背景图像。有了这个<div> 标签的默认状态display:none,当<span> 标签图像悬停在上面时,我希望它更改为display:block。我使用以下 css 行做到了这一点:
span.example4:hover + div.example5 { display: block; }
像梦一样工作!请记住,此 css 不适用于 IE6 或更低版本
【问题讨论】:
-
有可能,让我们看看你到目前为止得到了什么。 (单击edit 并添加您的代码)。您可能需要
<map>,如果您的“灯箱”仅加载图像,则需要使用onOpen回调或其他方法或加载 HTML 片段。 -
嗨,Wesley,抱歉耽搁了,我现在添加了一些代码,真的希望对您有所帮助!!
-
除了不能在 IE6 中工作之外,这也不适用于任何使用键盘导航的用户。您刚刚使屏幕阅读器用户完全无法访问该信息。
-
@steveax - 嗨,为反馈干杯。我完全错过了的好点,你知道一种可以在屏幕阅读器友好的同时实现它的方法吗?
标签: jquery html image lightbox imagemap