【问题标题】:Jquery not working Firefox and IE for action executed on link clickJquery 无法在 Firefox 和 IE 上运行,无法在单击链接时执行操作
【发布时间】:2017-08-31 14:39:26
【问题描述】:

我的页面在 Chrome 上运行良好,但在 IE 或 Firefox 上却不行。我把这个 Jsfiddle 放在一起,它显示了部分问题:https://fiddle.jshell.net/dkwsswdw/2/

如果您在 Chrome 上打开它,您应该可以单击窗口顶部的向下箭头并从 div 向下滚动到 div。如果您在 Firefox 或 IE 中打开它,它将停止工作。

有什么想法吗?我了解在 FF 和 IE 中无法正确调用 jQuery 存在问题,但我不确定它如何应用于此问题。 (我对此进行了广泛的研究,但我对 jQuery 还太陌生,无法弄清楚它是如何应用的。)

注意:

如果有帮助,这是我在 Wordpress 中运行的实际循环,用于显示帖子并将“当前”类添加到循环中的第一个帖子:

<?php

        // The Arguments
        $args = array(
            'post_type' => 'strange',
            'posts_per_page' =>-1, 
            'order_by' => 'menu_order'

        );

        $c = 0; 
        $class = ''; 

        // The Query
        $the_query = new WP_Query( $args ); ?>

        <?php

        // If we have the posts...
        if ( $the_query->have_posts() ) : ?>

        <!-- Start the loop the loop --> 
            <?php while ( $the_query->have_posts() ) : $the_query->the_post(); 
            $c++; 
            if ( $c == 1 ) $class .= ' current'; // if the item is the first item, add class current
            else $class = ''; 
            ?>

                <div id="strange-container" class="strange-container <?php echo $class; ?>">    

                    <img src="<?php the_field('strange-img'); ?>" alt="<?php the_title(); ?>" />

                    <span><?php the_field('strange-text'); ?></span>

                </div>

            <?php endwhile; endif; ?>

        <?php wp_reset_postdata(); ?>

【问题讨论】:

标签: javascript php jquery html cross-browser


【解决方案1】:

仅供参考,您的图片位于htpasswd 后面。

也就是说,有些浏览器喜欢在 body 上制作动画,而另一些浏览器喜欢在 html 上制作动画。更改如下所示的行:

$('body').animate({

到这里:

$('html,body').animate({

【讨论】:

  • 谢谢!这确实解决了它!有没有像 caniuse.com 这样的资源,我可以参考 jQuery 这样的浏览器首选项?编写自己的脚本对我来说是新事物,我希望能够更好地在线找到自己的解决方案。
  • 并不是我所知道的……这是您凭经验学到的东西之一。
  • 明白了。再次感谢。今天我一直在摆弄这个,事实证明这是一个简单的解决方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-08-20
  • 2010-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-18
相关资源
最近更新 更多