我使用CSS技巧的“平滑滚动”浏览我的一个页面(引导3)网站。 而且我也使用花式框来显示我的投资组合项目。平滑滚动与Fancybox冲突“追加自定义内容”
现在,一切工作正常,直到我试图与数据的fancybox显示的数据从一个div追加(持有的资产组合项内容)
我觉得这个冲突,因为两者的jQuery的(Smoothscroll和Fancybox)使用锚标签。
这里是smoothscroll脚本:
<script type="text/javascript">
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 500);
return false;
}
}
});
});
</script>
这里是脚本的fancybox这就是加载的fancybox,并与类触发它,也是会从一个单独的DIV内容的脚本。
<script type="text/javascript">
$(document).ready(function() {
$(".fancybox").fancybox();
});
</script>
<!--FANCYBOX DISPLAY CONTENT FROM DIV -->
<script type="text/javascript">
$(".fancybox").fancybox({
openEffect : 'none',
closeEffect : 'none',
afterLoad : function() {
this.inner.prepend('<h1>1. My custom title</h1>');
this.content = '<h1>2. My custom title</h1>' + this.content.html();
}
});
</script>
当我注释掉smoothscroll脚本时,fancybox工作正常。所以它必须是smoothscroll。
有关如何解决这个问题的任何想法?
你可以在这里看到的网站与的fancybox工作,所以smoothscroll被禁用: http://www.baasdesign.nl/responsive/
上面的代码与参考网站上的代码不对应。你有语法js错误(API选项恰好在'$(“。fancybox”)之后)fancybox();') – JFK