我正在尝试使用两块 jquery 作为灯箱和一个滚动条来构建我正在构建的单页网站。它们单独工作都很好,但是当我将它们放在同一页面上时,滚动条似乎取消了灯箱,使其无效。
这是灯箱代码:
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$("a[rel^='prettyPhoto']").prettyPhoto();
});
</script>
这是滚动条代码:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript">// <![CDATA[
$(document).ready(function() {
function filterPath(string) {
return string.replace(/^\//, '').replace(/(index|default).[a-zA-Z]{3,4}$/, '').replace(/\/$/, '');
}
$('a[href*=#]').each(function() {
if (filterPath(location.pathname) == filterPath(this.pathname) && location.hostname == this.hostname && this.hash.replace(/#/, '')) {
var $targetId = $(this.hash),
$targetAnchor = $('[name=' + this.hash.slice(1) + ']');
var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
if ($target) {
var targetOffset = $target.offset().top;
$(this).click(function() {
$('html, body').animate({
scrollTop: targetOffset
}, 2000);
return false;
});
}
}
});
});
// ]]></script>
我注意到您的滚动条代码包含 jquery.js 但 PrettyPhoto 代码不包含。在您的实际网页上,您应该在任一之前包含 jquery.js 一次$(document).ready()
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)