Comments (7)
我试了fancybox插件依然这样,看来跟点击放大图片冲突了
@Troy-Yang
from hexo-lazyload-image.
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.
from hexo-lazyload-image.
我用的也是lightgallery,按照您的代码在我这儿有语法错误,于是我改成了
$(document).find('img[data-original]').each(function(){
$(this).parent().href = $(this).attr("data-original");
});
还是不行,所以还是想请教一下您该怎么改才行,谢谢~ @Troy-Yang
from hexo-lazyload-image.
不好意思,怪我jQuery不怎么熟悉,代码这样改就OK啦
<script>
$(document).find('img[data-original]').each(function(){
$(this).parent().attr("href", $(this).attr("data-original"));
});
</script>
from hexo-lazyload-image.
已经在最新的1.0.6版本里专门对这种问题进行了修复,上面的代码不出意外应该可以删除了
from hexo-lazyload-image.
from hexo-lazyload-image.
Related Issues (20)
- 一个小小的建议 HOT 3
- I think the braces dependency needs to be updated. HOT 1
- 与Fancybox同时启用时产生冲突 HOT 1
- Bug:Picture in the sidebar is always loading HOT 5
- 安装插件后主页出现文字无法显示,只有博客框架和背景图片,请问怎么解决或者卸载 HOT 4
- 关于与 Pjax 的兼容问题 HOT 7
- 页面第一加载之后再刷新图片就不再加载了 HOT 2
- onlypost is not work HOT 2
- 如何固定懒加载图片占位符 HOT 5
- 懒加载不工作 HOT 1
- [FR] Load before it comes into the browser viewport HOT 4
- 几个功能增强建议 HOT 6
- 回调函数 HOT 1
- script.js文件中修改了97后前四张图还是loading占位 HOT 3
- onlypost 为true时 不工作 HOT 8
- 如何取消某页面懒加载 HOT 3
- next开启懒加载后报错 HOT 7
- 懒加载 小建议 HOT 1
- 与 fancybox 的兼容问题 HOT 3
- 与 hexo-blog-encrypt 插件的兼容问题 HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hexo-lazyload-image.