我正在研究fancybox功能。它工作正常,但它没有基于我的Rel。
进行分组这里是javascipt
<script type="text/javascript">
$(function($){
var addToAll = false;
var gallery = true;
var titlePosition = 'inside';
$(addToAll ? 'img' : 'img.fancybox').each(function(){
var $this = $(this);
var title = $this.attr('title');
var src = $this.attr('data-big') || $this.attr('src');
var a = $('<a href="#" class="fancybox"></a>').attr('href', src).attr('title', title);
$this.wrap(a);
});
if (gallery)
$('a.fancybox').fancybox({
titlePosition: titlePosition
});
});
$.noConflict();
</script>
HTML
<img class="fancybox" title="Bed" rel="1roomGD" src="images_1" alt="Bed" />
<img class="fancybox" title="K" rel="1roomGD" src="images_2" alt="K" />
<img class="fancybox" title="G" rel="2roomS" src="images_3" alt="G" />
答案 0 :(得分:0)
根据@JFK的建议,我发现更少的代码修改解决方案是添加.attr(&#39; rel&#39;)来从img中获取值
<script type="text/javascript">
$(function($){
var addToAll = false;
var gallery = true;
var titlePosition = 'inside';
$(addToAll ? 'img' : 'img.fancybox').each(function(){
var $this = $(this);
var title = $this.attr('title');
var src = $this.attr('data-big') || $this.attr('src');
var rel = $this.attr('rel')
var a = $('<a href="#" class="fancybox"></a>').attr('href', src).attr('title', title).attr('rel',rel);
$this.wrap(a);
});
if (gallery)
$('a.fancybox').fancybox({
titlePosition: titlePosition
});
});
$.noConflict();
</script>