簡體   English   中英

無法讀取未定義的屬性“top”(腳本沖突?)

[英]Cannot read property 'top' of undefined (script conflict?)

我有一個像這樣的腳本:

分頁.js

var busy = false;
jQuery(window).scroll(function () {
    if (jQuery(window).scrollTop() > 300) {
        jQuery('#scrollUp').stop().animate({
            opacity: 0.05
        }, 400)
    } else {
        jQuery('#scrollUp').stop().animate({
            opacity: 0.00
        }, 400)
    }
    if (jQuery(window).scrollTop() + jQuery(window).height() > jQuery('#main_content').offset().top + jQuery('#main_content').height() - 50 && !busy) {
        busy = true;
        link = jQuery('.pagination .nextpage').attr('href');
        if (typeof link != 'undefined') {
            var params = 'smt_layout=' + jQuery('body').attr('layout') + '&ajaxpage=1';
            jQuery.ajax({
                type: "POST",
                cache: false,
                async: false,
                data: params,
                url: link,
                dataType: 'json',
                success: function (data) {
                    if (data != "") {
                        jQuery('.pagination .nextpage').parent().append('<span class="thispage">Page ' + jQuery('.pagination .nextpage').attr('alt') + '</span>');
                        jQuery('.pagination .nextpage').remove();
                        jQuery("#main_content").append(data['content']);
                        busy = false
                    }
                }
            })
        }
    }
});
jQuery('#scrollUp').live('mouseenter', function () {
    jQuery(this).stop().animate({
        opacity: 0.1
    }, "slow")
}).live('mouseout', function () {
    if (jQuery(window).scrollTop() > 300) var o = 0.05;
    else var o = 0.00;
    jQuery(this).stop().animate({
        opacity: o
    }, "slow")
});
jQuery('#scrollUp').live('click', function () {
    jQuery('html, body').animate({
        scrollTop: 0
    }, 1200);
});

我在 Photonic Gallery Wordpress 插件上使用 Magnific Popup:

magnific.js

我收到一個錯誤:未捕獲的類型錯誤:無法在 pagination.js:1 處讀取未定義的屬性 'top'

它看起來像一個jQuery沖突嗎? 你能告訴我如何解決這個問題嗎? 先感謝您。

它失敗了: jQuery('#main_content').offset().top

確保:

  • 在設置這些處理程序之前運行jQuery(document).ready()
  • 您有一個 ID 為main_content的 DOM 元素。

這是實現腳本的函數:

 function headtext() { if( (is_archive()&&is_day()&&$this->get( 'seo', 'day' ))|| (is_archive()&&is_month()&&$this->get( 'seo', 'month' ))|| (is_archive()&&is_year()&&$this->get( 'seo', 'year' ))|| (is_category()&&$this->get( 'seo', 'category' ))|| (is_tag()&&$this->get( 'seo', 'tag' ))|| (is_author()&&$this->get( 'seo', 'author' ))|| (is_search()&&$this->get( 'seo', 'search' )) ) { ?><meta name="robots" content="noindex" /><?php } if ($this->get( 'general', 'favicon' )) echo '<link rel="shortcut icon" href="' . $this->get( 'general', 'favicon' ) . '" type="image/x-icon" />' . "\\n"; if ($this->get( 'integration', 'rss' )) { echo '<link rel="alternate" type="application/rss+xml" title="RSS Feed" href="' . $this->get( 'integration', 'rss' ) . '" />' . "\\n"; } if ($this->get( 'layout', 'pagination' )) { ?> <script type="text/javascript" src="<?php echo get_template_directory_uri()?>/js/pagination.js"></script> <?php } ?> <link rel="stylesheet" href="<?php echo get_template_directory_uri()?>/css/wide.css" type="text/css" media="screen and (min-width:1024px)" /> <!--[if lt IE 9]> <link rel="stylesheet" href="<?php echo get_template_directory_uri()?>/css/wide.css" type="text/css" media="screen" /> <link rel="stylesheet" href="<?php echo get_template_directory_uri()?>/css/ie.css" type="text/css" media="screen" /> <![endif]--> <link rel="stylesheet" href="<?php echo get_template_directory_uri()?>/css/mobile.css" type="text/css" media="screen and (min-width:240px) and (max-width:639px)" /> <link rel="stylesheet" href="<?php echo get_template_directory_uri()?>/css/tablet.css" type="text/css" media="screen and (min-width:640px) and (max-width:1023px)" /> <?php if ($this->get( 'integration', 'ecwidcss' )) { ?> <link rel="stylesheet" href="<?php echo get_template_directory_uri()?>/css/ecwid.css" type="text/css" /> <?php } ?> <link rel="stylesheet" href="<?php echo get_template_directory_uri()?>/css/shortcode.css" type="text/css" media="screen, projection" /> <script src="<?php echo get_template_directory_uri()?>/js/jquery.cycle.all.js" type="text/javascript"></script> <?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); ?> <script type="text/javascript"> jQuery(document).ready(function() { <?php $this->block_slider_config(); ?> jQuery(".menus .children").addClass('sub-menu'); <?php $this->block_menu_config("menus"); ?> jQuery('textarea[name="comment"]').each(function(){ jQuery(this).attr('name','<?php echo $_SESSION['commentinput']; ?>'); }); }); </script> <?php }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM