我正在使用两个不同的jQuery函数,一个似乎正在取消另一个



我正在尝试为我正在构建的单页网站使用两块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但漂亮的照片代码没有。在你的实际网页上,你应该在$(document).ready()之前.js一次包含jquery。

最新更新