Git Product home page Git Product logo

Comments (7)

tiexo avatar tiexo commented on June 28, 2024

我试了fancybox插件依然这样,看来跟点击放大图片冲突了
@Troy-Yang

from hexo-lazyload-image.

Troy-Yang avatar Troy-Yang commented on June 28, 2024

Hi @tiexo

我能通过Landscape重现你说的fancybox图片问题,看了一下原因,是因为fancybox会在页面加载完成后在所有img外再次包装一层a元素并把img的src复制给其href,如下:

<a href="https://troyyang.com/images/loading.png" title="image" class="fancybox" rel="article1">
     <img src="https://troyyang.com/images/loading.png" data-original="https://images.troyyang.com/2017-6-25-js-inherence.png" alt="image">
</a>

从上可以看到,页面加载后此时所有图片还是使用的loading图片从而导致fancybox把真实图片找错了。而lazyload只有在图片在可视区域时才把img的src替换为真实图片。

作为fancybox的解决方案,可以把https://github.com/hexojs/hexo-theme-landscape/blob/master/source/js/script.js中的97行

$(this).wrap('<a href="' + this.src + '" title="' + alt + '" class="fancybox"></a>');

改为

      $(this).wrap('<a href="' + ($(this).attr("data-original")?$(this).attr("data-original"):this.src) + '" title="' + alt + '" class="fancybox"></a>');

至于lightgallery,我并没有一个在线的hexo demo,但我看了一下那个类库,也看了他的demo,发现和fancybox的问题差不多,解决方案也差不多就是把新增的a元素中的href值替换为data-original中的值,如果你能提供下你的hexo网站地址,我可以帮你具体看看。

类似于在$("#lightgallery").lightGallery(); 执行后运行下面的代码(未测试):

$(document).find('img[data-original]').foreach(  
function(){
 $(this).parent().href = this.attributions.data-original
}  )

希望有帮助。

from hexo-lazyload-image.

tiexo avatar tiexo commented on June 28, 2024

from hexo-lazyload-image.

ShawyerPeng avatar ShawyerPeng commented on June 28, 2024

我用的也是lightgallery,按照您的代码在我这儿有语法错误,于是我改成了

$(document).find('img[data-original]').each(function(){
     $(this).parent().href = $(this).attr("data-original");
});

还是不行,所以还是想请教一下您该怎么改才行,谢谢~ @Troy-Yang

from hexo-lazyload-image.

ShawyerPeng avatar ShawyerPeng commented on June 28, 2024

不好意思,怪我jQuery不怎么熟悉,代码这样改就OK啦

<script>
    $(document).find('img[data-original]').each(function(){
        $(this).parent().attr("href", $(this).attr("data-original"));
    });
</script>

from hexo-lazyload-image.

Troy-Yang avatar Troy-Yang commented on June 28, 2024

已经在最新的1.0.6版本里专门对这种问题进行了修复,上面的代码不出意外应该可以删除了

from hexo-lazyload-image.

tiexo avatar tiexo commented on June 28, 2024

from hexo-lazyload-image.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.