【发布时间】:2016-05-28 20:14:11
【问题描述】:
我似乎有一个问题,我的 jQuery 函数似乎无法在所有 IE 版本中运行,但这些函数似乎在 Chrome、Safari 和 Firefox 中运行良好。
它甚至不能在 IE 11 / Windows 10 中运行。
我有什么遗漏吗?
感谢您的帮助。
(function($) {
'use strict';
$(document).ready(function() {
(function(){
if (!/portfolio-item/.test(window.location.href)) return;
var i;
var bigwrap = document.querySelector('.page-header .portfolio-entry-img').parentNode;
var bigimages = {};
var products = document.querySelectorAll('.product-thumbnail-wrap img');
var title = document.querySelector('.product-title');
var code = document.querySelector('.product-code');
var trays_tmp = document.querySelectorAll('.tray-reference [data-tray]');
var trays = {};
var wraps_tmp = document.querySelectorAll('.tray-wrap');
var wraps = {};
var active = {};
active.bigimage = bigwrap.firstElementChild;
if(active.bigimage) bigimages[active.bigimage.src] = active.bigimage;
for(i in Object.keys(trays_tmp)) {
if (trays_tmp.hasOwnProperty(i)) {
trays[trays_tmp[i].dataset.tray] = trays_tmp[i];
if(/tray-active/.test(trays_tmp[i].className)) active.tray = trays_tmp[i].dataset.tray;
}
}
for(i in Object.keys(wraps_tmp)) {
if (wraps_tmp.hasOwnProperty(i)) {
var table = wraps_tmp[i].dataset.table;
wraps[table] = wraps_tmp[i];
if(wraps_tmp[i].style.display === '') active.wrap = wraps_tmp[i];
}
}
for (i in Object.keys(products)) {
if (products.hasOwnProperty(i)) {
if (/product-thumb-active/.test(products[i].className)) active.product = products[i];
if (products[i].dataset.big && !bigwrap.querySelector('[src="' + products[i].dataset.big + '"]') && active.bigimage) {
var bigimg = active.bigimage.cloneNode();
bigimg.src = products[i].dataset.big;
bigimg.style.display = 'none';
bigwrap.appendChild(bigimg);
bigimages[products[i].dataset.big] = bigimg;
}
products[i].addEventListener('click', function() {
if (active.product) active.product.className = active.product.className.replace(/\s*product-thumb-active/, '');
this.className += ' product-thumb-active';
active.product = this;
if (active.tray) trays[active.tray].className = trays[active.tray].className.replace(/\s*tray-active/, '');
active.tray = this.dataset.tray;
if (active.tray){
if (!trays[active.tray]) active.tray = undefined;
else trays[active.tray].className += ' tray-active';
}
console.log(active.tray, trays[active.tray]);
if ((active.tray && active.wrap !== active.tray[0]) || !active.tray) {
if (active.wrap) active.wrap.style.display = 'none';
if (!active.tray) active.wrap = wraps.None;
else active.wrap = wraps[active.tray[0]];
if (!active.wrap) active.wrap = wraps.None;
active.wrap.style.display = '';
}
title.textContent = this.getAttribute('title');
code.textContent = this.getAttribute('code');
if (active.bigimage) active.bigimage.style.display = 'none';
active.bigimage = bigimages[this.dataset.big];
$(active.bigimage).fadeIn('fast');
});
}
}
})();
$(".nav-toggle").click(function() {
$(this).toggleClass("active");
$(".overlay-boxify").toggleClass("open");
$("#site-navigation-wrap").toggleClass("menuActive");
$(".fixed-logo").toggleClass("logoActive");
$("#site-social-wrap").toggleClass("socialActive");
});
$(".overlay ul li a").click(function() {
$(".nav-toggle").toggleClass("active");
$(".overlay-boxify").toggleClass("open");
$("#site-navigation-wrap").toggleClass("menuActive");
$(".fixed-logo").toggleClass("logoActive");
});
$(".overlay").click(function() {
$(".nav-toggle").toggleClass("active");
$(".overlay-boxify").toggleClass("open");
$("#site-navigation-wrap").toggleClass("menuActive");
$(".fixed-logo").toggleClass("logoActive");
});
$('.single-question').click(function() {
$('.tray-reference').toggle();
});
/***************** Header BG Scroll ******************/
var pastWaypoint = false;
$(window).scroll(function() {
if ($(window).scrollTop() > 580 && !pastWaypoint) {
$('.fixed-logo').show();
$(".fixed-header").addClass("hasBg header-sml");
$("#site-navigation-wrap").show();
console.log('d');
pastWaypoint = true;
} else if ($(window).scrollTop() <= 580 && pastWaypoint) {
$('.fixed-logo').hide();
console.log('f');
$(".fixed-header").removeClass("hasBg header-sml");
pastWaypoint = false;
}
});
$('.menu-item a[href^="#"]').on('click', function(e) {
e.preventDefault();
var target = this.hash;
var $target = $(target);
$('html, body').stop().animate({
'scrollTop': $target.offset().top
}, 900, 'swing', function() {
window.location.hash = target;
});
});
$("img").bind("contextmenu", function(e) {
return false;
});
$("div.desc").hide();
$("input[name$='requestbrochure']").change(function() {
$("div.desc").hide();
$("#" + this.value).show();
}).filter(function() {
return this.checked;
}).change();
$(".resource-tabs-menu a").click(function(event) {
event.preventDefault();
$(this).parent().addClass("resource-current");
$(this).parent().siblings().removeClass("resource-current");
var tab = $(this).attr("href");
$(".resource-tab-content").not(tab).css("display", "none");
$(tab).fadeIn();
});
$('.portfolio-dropdown-content').show();
$('#portfolio-dropdown-menu').click(function() {
$('.portfolio-dropdown-content').slideToggle("fast");
$('#portfolio-dropdown-icon').toggleClass("portfolio-dropdown-selected");
});
$('.request-brochure-button').click(function() {
$('.request-brochure-content').slideToggle("fast");
$('.request-brochure-button').toggleClass("request-brochure-button-active");
});
// Main menu superfish
$('ul.sf-menu').superfish({
delay: 200,
animation: {
opacity: 'show',
height: 'show'
},
speed: 'fast',
cssArrows: false,
disableHI: true
});
// Mobile Menu
$('#navigation-toggle').sidr({
name: 'sidr-main',
source: '#sidr-close, #site-navigation, #mobile-search',
side: 'left'
});
$('.sidr-class-toggle-sidr-close').click(function() {
$.sidr('close', 'sidr-main');
return false;
});
// Close the menu on window change
$(window).resize(function() {
$.sidr('close', 'sidr-main');
});
$("#featuresSlider").flickity({
cellAlign: "left",
contain: true,
prevNextButtons: false
});
$("#showcaseSlider").flickity({
cellAlign: "left",
contain: true,
prevNextButtons: false,
imagesLoaded: true
});
$(".youtube-media").on("click", function(e) {
var t = $(window).width();
if (t <= 768) {
return
}
$.fancybox({
href: this.href,
padding: 4,
type: "iframe",
href: this.href.replace(new RegExp("watch\\?v=", "i"), "v/")
});
return false;
});
$("a.single_image").fancybox({
padding: 4
});
$(".nav-toggle").click(function() {
$(this).toggleClass("active");
$(".overlay-boxify").toggleClass("open")
});
$(".overlay ul li a").click(function() {
$(".nav-toggle").toggleClass("active");
$(".overlay-boxify").toggleClass("open")
});
$(".overlay").click(function() {
$(".nav-toggle").toggleClass("active");
$(".overlay-boxify").toggleClass("open")
});
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top - 125
}, 1000);
return false;
}
}
});
}); // End doc ready
$(window).load(function() {
// Homepage FlexSlider
$('#homepage-slider').flexslider({
animation: 'slide',
slideshow: true,
smoothHeight: true,
controlNav: false,
directionNav: true,
prevText: '<span class="fa fa-angle-left"></span>',
nextText: '<span class="fa fa-angle-right"></span>',
controlsContainer: ".flexslider-container"
});
// Post FlexSlider
$('div.post-slider').flexslider({
animation: 'slide',
slideshow: true,
smoothHeight: true,
controlNav: false,
directionNav: true,
prevText: '<span class="fa fa-angle-left"></span>',
nextText: '<span class="fa fa-angle-right"></span>',
controlsContainer: ".flexslider-container"
});
}); // End on window load
})(jQuery);
【问题讨论】:
-
你能试试
if (typeof jQuery == 'undefined') {alert('no jquery');}你能告诉我你使用的是哪个版本的jQuery吗?据我所知,2.x 不适用于 IE 9 或更低版本 -
呢? @PeterS
-
代码中的任何地方,编辑:来自 jQuery 文档
jQuery 2.x has the same API as jQuery 1.x, but does not support Internet Explorer 6, 7, or 8.,在您的 IE 11 中,是否启用了 JavaScript? -
@PeterS SORRY 不起作用。这是做什么的?编辑:我正在使用 jQuery v1.11.3
-
@PeterS - 它似乎在 Windows XP / IE8 中工作
标签: javascript jquery internet-explorer browser cross-browser