0

我的 /js/global.js 文件中的这部分代码会在单击时激活每个图像以在新窗口中打开。是否可以更改此代码以在 FancyBox 中打开每个代码?我已经为我正在运行的 Vanilla 论坛下载了一个 FancyBox 插件,它目前仅针对您单击帖子本身后嵌入在帖子中的图像。在主页上,单击图像会打开一个新窗口。

// Shrink large images to fit into message space, and pop into new window when clicked.
// This needs to happen in onload because otherwise the image sizes are not yet known.
    jQuery(window).load(function() {
       var props = ['Width', 'Height'], prop;
       while (prop = props.pop()) {
          (function (natural, prop) {
             jQuery.fn[natural] = (natural in new Image()) ? 
             function () {
                return this[0][natural];
             } : 
             function () {
                var 
                   node = this[0],
                   img,
                   value;
                if (node.tagName.toLowerCase() === 'img') {
                   img = new Image();
                   img.src = node.src,
                   value = img[prop];
                }
                return value;
             };
          }('natural' + prop, prop.toLowerCase()));
       }
       jQuery('div.Message img').each(function(i,img) {
          var img = jQuery(img);
          var container = img.closest('div.Message');
          if (img.naturalWidth() > container.width() && container.width() > 0) {
             img.wrap('<a href="'+$(img).attr('src')+'"></a>');
          }
       });
       // Let the world know we're done here
       jQuery(window).trigger('ImagesResized');
    });
4

1 回答 1

0

将特定添加到包装的图像中,修改此行

img.wrap('<a href="'+$(img).attr('src')+'"></a>');

...进入这个:

img.wrap('<a class="fancybox" href="'+$(img).attr('src')+'"></a>');

.fancybox然后在自定义脚本中将fancybox绑定到该选择器(“ ”),例如:

$(".fancybox").fancybox();

这假设您已正确加载了 fancybox js 和 css 文件。

于 2013-02-27T20:53:11.713 回答