jQuery не работает в IE - PullRequest
0 голосов
/ 24 мая 2011

У меня проблема с запуском моих сценариев jQuery в Internet Explorer на моих сайтах Wordpress.В Firefox и Chrome он работает без сбоев, но IE не хочет играть со мной.

Я думаю, что это может быть конфликтом в jQuery в Wordpress, потому что мой скрипт хорошо работает с простыми «переменными $».Я использую "jQueryvariable", как они говорят в http://wordpress.org/support/topic/using-jquery-in-own-plugins#post-687280, но в IE все еще не работает.

Кто-нибудь может сказать мне, как правильно включить мои собственные файлы jQuery в WordPress?

Большое спасибо за помощь.


function MoveItems() {
    jQuery('.container>div:first').animate({
        width: '0px'
    }, 1000, function () {
        var mine = jQuery(this);
        mine.parent().append(mine);
        jQuery(this).css({
            width: '120px'
        });
    });
    jQuery('#bands>h2:first').fadeTo(
    4000, 0, function () {
        var mine = jQuery(this);
        mine.parent().append(mine);
        jQuery(this).fadeTo(
        1, 1);
    });
};



jQuery(document).ready(function () {

    var timer = setInterval(MoveItems, 1000);

    jQuery('#sponsors').hover(function () {
        clearInterval(timer);
    }, function () {
        timer = setInterval(MoveItems, 1000);
    });

    jQuery('.sponsor').mouseover(function () {
        jQuery('img', this).animate({
            width: "200px",
            height: "200px",
            left: "-40px",
            top: "-40px"
        }, {
            queue: false,
            duration: 500
        });
    });

    jQuery('.sponsor').mouseleave(function () {
        jQuery('img', this).animate({
            width: "120px",
            height: "120px",
            left: "0px",
            top: "0px"
        }, {
            queue: false,
            duration: 500
        });
    });

});

Ответы [ 4 ]

2 голосов
/ 31 мая 2011

ОК, у меня есть решение. В последних версиях WordPress есть известная ошибка с jquery и ie8 (иногда оперой).

подробнее об ошибке здесь: https://wordpress.stackexchange.com/questions/10719/jquery-in-ie8-no-longer-works-after-3-1-upgrade

РЕШЕНИЕ:

//Making jQuery Google API
function modify_jquery() {
    if (!is_admin()) {
        // comment out the next two lines to load the local copy of jQuery
        wp_deregister_script('jquery');
        wp_register_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js', false, '1.6.1');
        wp_enqueue_script('jquery');
    }
}
add_action('init', 'modify_jquery');
0 голосов
/ 24 мая 2011

Включите ту часть Jquery, которая, по вашему мнению, может конфликтовать с wordpress, в

        jQuery.noConflict();
        (function($){

           // type your jquery here 

         })(jQuery) ;

посмотрите, работает ли она.

0 голосов
/ 25 мая 2011

IE не нравится, как вы присваиваете некоторые переменные. Также может быть, что IE думает, что контейнер является глобальной переменной.

Посмотрите, поможет ли это. Тело может быть любым родительским контейнером контейнера.

function MoveItems() {
    jQuery('body').append('.container>div:first').animate({
        width: '0px'
    }, 1000, function () {
        var mine = jQuery(this);
        mine.parent().append(mine);
        jQuery(this).css({
            width: '120px'
        });
    });
    jQuery('body').append('#bands>h2:first').fadeTo(
    4000, 0, function () {
        var mine = jQuery(this);
        mine.parent().append(mine);
        jQuery(this).fadeTo(
        1, 1);
    });
}  //removed this semi colon based on error from jslint.

jQuery(document).ready(function () {
    var timer = setInterval(MoveItems, 1000);
    jQuery('#sponsors').hover(function () {
        clearInterval(timer);
    }, function () {
        timer = setInterval(MoveItems, 1000);
    });

    jQuery('.sponsor').mouseover(function () {
        jQuery('img', this).animate({
            width: "200px",
            height: "200px",
            left: "-40px",
            top: "-40px"
        }, {
            queue: false,
            duration: 500
        });
    });

    jQuery('.sponsor').mouseleave(function () {
        jQuery('img', this).animate({
            width: "120px",
            height: "120px",
            left: "0px",
            top: "0px"
        }, {
            queue: false,
            duration: 500
        });
    });

}); 

Звучит неправдоподобно, но я видел ту же ошибку на Ie, вызванную проблемами с реестром, повреждающими движок JavaScript.

Если код не работает, посмотрите, можете ли вы попробовать его на другом компьютере с IE.

Я также заметил, что у вас есть ошибки типа MIME для всех ваших файлов JavaScript. Может быть, не причина этой проблемы, а что-то еще, на что стоит взглянуть.

Resource interpreted as Script but transferred with MIME type application/octet-stream.
wp-scriptaculous.js:-1Resource interpreted as Script but transferred with MIME type application/octet-stream.
prototype.js:-1Resource interpreted as Script but transferred with MIME type application/octet-stream.
effects.js:-1Resource interpreted as Script but transferred with MIME type application/octet-stream.
lightbox.js:-1Resource interpreted as Script but transferred with MIME type application/octet-stream.
jquery.js:-1Resource interpreted as Script but transferred with MIME type application/octet-stream.
jquery.cycle.all.min.js:-1Resource interpreted as Script but transferred with MIME type application/octet-stream.
ngg.slideshow.min.js:-1Resource interpreted as Script but transferred with MIME type application/octet-stream.
webtoolkit.sprintf.js:-1Resource interpreted as Script but transferred with MIME type application/octet-stream.
fergcorp_countdownTimer_java.js:-1Resource interpreted as Script but transferred with MIME type application/octet-stream.
blink2_backup.js:-1Resource interpreted as Script but transferred with MIME type application/octet-stream.
0 голосов
/ 24 мая 2011

Попробуйте сначала добавить это:

jQuery(document).ready(function($) { // When the document (page) has finished loading.

alert("jQuery is working!"); // Shows a window displaying "jQuery is working!"

}); 

и посмотрите, отображается предупреждение или нет ... Если отображается предупреждение, то это не проблема jquery, я думаю

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...