0

我正在尝试将两块 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>
4

1 回答 1

1

我注意到您的滚动代码包含 jquery.js 但 prettyPhoto 代码不包含。在您的实际网页上,您应该只包含一次 jquery.js,在任何一个$(document).ready().

于 2012-05-10T06:41:33.833 回答