繁体   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