求助帮看下一段JS代码和IE7不兼容

cctv361 2015-10-09 06:18:51
下面,这段JS代码和IE7不兼容,在IE7打开网页会停顿好半天,1-2分钟,然后弹出提示框,说运行什么会导致变慢类似的提示,,在IE7以上的都正常。。帮忙看下,感谢。



/*
* File: jquery.flexisel.js
* Version: 1.0.1
* Description: Responsive carousel jQuery plugin
* Author: 9bit Studios
* Copyright 2012, 9bit Studios
* http://www.9bitstudios.com
* Free to use and abuse under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
*/

(function ($) {

$.fn.flexisel = function (options) {

var defaults = $.extend({
visibleItems: 4,
animationSpeed: 200,
autoPlay: false,
autoPlaySpeed: 3000,
pauseOnHover: true,
setMaxWidthAndHeight: false,
enableResponsiveBreakpoints: false,
responsiveBreakpoints: {

portrait: {
changePoint:480,
visibleItems: 1
},
landscape: {
changePoint:640,
visibleItems: 2
},
tablet: {
changePoint:768,
visibleItems: 3
}
}
}, options);

/******************************
Private Variables
*******************************/

var object = $(this);
var settings = $.extend(defaults, options);
var itemsWidth; // Declare the global width of each item in carousel
var canNavigate = true;
var itemsVisible = settings.visibleItems;
var responsivePoints = [];

/******************************
Public Methods
*******************************/

var methods = {

init: function() {

return this.each(function () {
methods.appendHTML();
methods.setEventHandlers();
methods.initializeItems();

});
},

/******************************
Initialize Items
Set up carousel
*******************************/

initializeItems: function() {

var listParent = object.parent();
var innerHeight = listParent.height();
var childSet = object.children();
methods.sortResponsiveObject(settings.responsiveBreakpoints);

var innerWidth = listParent.width(); // Set widths
itemsWidth = (innerWidth)/itemsVisible;
childSet.width(itemsWidth);
childSet.last().insertBefore(childSet.first());
childSet.last().insertBefore(childSet.first());
object.css({'left' : -itemsWidth});

object.fadeIn();
$(window).trigger("resize"); // needed to position arrows correctly

},


/******************************
Append HTML
Wrap list in markup with classes needed for carousel to function
*******************************/

appendHTML: function() {

object.addClass("nbs-flexisel-ul");
object.wrap("<div class='nbs-flexisel-container'><div class='nbs-flexisel-inner'></div></div>");
object.find("li").addClass("nbs-flexisel-item");

if(settings.setMaxWidthAndHeight) {
var baseWidth = $(".nbs-flexisel-item img").width();
var baseHeight = $(".nbs-flexisel-item img").height();
$(".nbs-flexisel-item img").css("max-width", baseWidth);
$(".nbs-flexisel-item img").css("max-height", baseHeight);
}

$("<div class='nbs-flexisel-nav-left'></div><div class='nbs-flexisel-nav-right'></div>").insertAfter(object);
var cloneContent = object.children().clone();
object.append(cloneContent);
},


/******************************
Set Event Handlers
Set events for carousel
*******************************/
setEventHandlers: function() {

var listParent = object.parent();
var childSet = object.children();
var leftArrow = listParent.find($(".nbs-flexisel-nav-left"));
var rightArrow = listParent.find($(".nbs-flexisel-nav-right"));

$(window).on("resize", function(event){

methods.setResponsiveEvents();

var innerWidth = $(listParent).width();
var innerHeight = $(listParent).height();

itemsWidth = (innerWidth)/itemsVisible;

childSet.width(itemsWidth);
object.css({'left' : -itemsWidth});

var halfArrowHeight = (leftArrow.height())/2;
var arrowMargin = (innerHeight/2) - halfArrowHeight;
leftArrow.css("top", arrowMargin + "px");
rightArrow.css("top", arrowMargin + "px");

});

$(leftArrow).on("click", function (event) {
methods.scrollLeft();
});

$(rightArrow).on("click", function (event) {
methods.scrollRight();
});

if(settings.pauseOnHover) {
$(".nbs-flexisel-item").on({
mouseenter: function () {
canNavigate = false;
},
mouseleave: function () {
canNavigate = true;
}
});
}

if(settings.autoPlay) {

setInterval(function () {
if(canNavigate)
methods.scrollRight();
}, settings.autoPlaySpeed);
}

},

/******************************
Set Responsive Events
Set breakpoints depending on responsiveBreakpoints
*******************************/

setResponsiveEvents: function() {
var contentWidth = $('html').width();

if(settings.enableResponsiveBreakpoints) {

var largestCustom = responsivePoints[responsivePoints.length-1].changePoint; // sorted array

for(var i in responsivePoints) {

if(contentWidth >= largestCustom) { // set to default if width greater than largest custom responsiveBreakpoint
itemsVisible = settings.visibleItems;
break;
}
else { // determine custom responsiveBreakpoint to use

if(contentWidth < responsivePoints[i].changePoint) {
itemsVisible = responsivePoints[i].visibleItems;
break;
}
else
continue;
}
}
}
},

/******************************
Sort Responsive Object
Gets all the settings in resposiveBreakpoints and sorts them into an array
*******************************/

sortResponsiveObject: function(obj) {

var responsiveObjects = [];

for(var i in obj) {
responsiveObjects.push(obj[i]);
}

responsiveObjects.sort(function(a, b) {
return a.changePoint - b.changePoint;
});

responsivePoints = responsiveObjects;
},

/******************************
Scroll Left
Scrolls the carousel to the left
*******************************/

scrollLeft:function() {

if(canNavigate) {
canNavigate = false;

var listParent = object.parent();
var innerWidth = listParent.width();

itemsWidth = (innerWidth)/itemsVisible;

var childSet = object.children();

object.animate({
'left' : "+=" + itemsWidth
},
{
queue:false,
duration:settings.animationSpeed,
easing: "linear",
complete: function() {
childSet.last().insertBefore(childSet.first()); // Get the first list item and put it after the last list item (that's how the infinite effects is made)
methods.adjustScroll();
canNavigate = true;
}
}
);
}
},

/******************************
Scroll Right
Scrolls the carousel to the right
*******************************/

scrollRight:function() {

if(canNavigate) {
canNavigate = false;

var listParent = object.parent();
var innerWidth = listParent.width();

itemsWidth = (innerWidth)/itemsVisible;

var childSet = object.children();

object.animate({
'left' : "-=" + itemsWidth
},
{
queue:false,
duration:settings.animationSpeed,
easing: "linear",
complete: function() {
childSet.first().insertAfter(childSet.last()); // Get the first list item and put it after the last list item (that's how the infinite effects is made)
methods.adjustScroll();
canNavigate = true;
}
}
);
}
},

/******************************
Adjust Scroll
Needed to position arrows correctly on init and resize
*******************************/

adjustScroll: function() {

var listParent = object.parent();
var childSet = object.children();

var innerWidth = listParent.width();
itemsWidth = (innerWidth)/itemsVisible;
childSet.width(itemsWidth);
object.css({'left' : -itemsWidth});
}

};

if (methods[options]) { // $("#element").pluginName('methodName', 'arg1', 'arg2');
return methods[options].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof options === 'object' || !options) { // $("#element").pluginName({ option: 1, option:2 });
return methods.init.apply(this);
} else {
$.error( 'Method "' + method + '" does not exist in flexisel plugin!');
}
};

})(jQuery);
...全文
308 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
cctv361 2015-10-14
  • 打赏
  • 举报
回复
谁回个贴也好,让我结下呢,
cctv361 2015-10-14
  • 打赏
  • 举报
回复
引用 4 楼 jikeytang 的回复:
这个只是一个插件,不是主要的原因。主要的可能是jquery的主版本,现在已经需要区分是否兼容ie低版本了。 有可能是这个原因, jQuery 2.x has the same API as jQuery 1.x, but does not support Internet Explorer 6, 7, or 8 http://jquery.com/download/ 选择是非2.x的jquery。 看看是不是这个原因。
感谢 回复,,这个插件就是控制菜单下拉及图片左右滚动。。去掉这两个效果就有了,在IE7中网页打开正常。。加上在IE7加载半天,出现错误提示。 问题超出完全没有基础的我。先不弄了,结了
豪情 2015-10-14
  • 打赏
  • 举报
回复
这个只是一个插件,不是主要的原因。主要的可能是jquery的主版本,现在已经需要区分是否兼容ie低版本了。 有可能是这个原因, jQuery 2.x has the same API as jQuery 1.x, but does not support Internet Explorer 6, 7, or 8 http://jquery.com/download/ 选择是非2.x的jquery。 看看是不是这个原因。
cctv361 2015-10-11
  • 打赏
  • 举报
回复
cctv361 2015-10-10
  • 打赏
  • 举报
回复
没有人知道呢,谢谢

87,955

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧