我正在尝试修改Coda-Slider2.0 (http://www.ndoherty.biz/tag/coda-slider/)以使用基于百分比的宽度,而不是硬编码的像素宽度,以允许流体大小调整。我已经让它工作的很好了,除了当我试图移回第一个面板时,IE7出现了一个小故障(火狐没有表现出这种行为)。
当我运行coda-slider 2.0附带的默认index.html时,一切在IE7中都运行得很好。然后我插入图像,而不是默认的文本,这也很好用。然后,我将CSS和JS更改为使用百分比宽度-这非常有效,除非我尝试返回到第一个面板-当我这样做时,比方说,从面板4,而不是平滑地动画回到面板1,视图立即跳到面板1和面板2之间的中间,然后动画回到面板1。
这可以在我设置的测试站点上看到:
http://www.lootcorp.com/animateissue/
下面是我正在使用的修改后的Coda-Slider JS文件的源代码。注为了简化调试,我去掉了所有不必要的代码。
问题与线路有关:
offset = - (panelWidth*z) + "%";我想可能动画不喜欢输入"0%“作为值,所以我尝试在面板1被选中时输入"0”和"0px“-同样的结果。最终结果是正确的-最终div被正确地定位在空白处-left: 0,但我不知道为什么在这样做之前它会跳到面板1和2中间的位置。(从面板4到3或2的动画效果良好)。我尝试使用'left‘而不是’margin left‘,结果是一样的。
Bug还是愚蠢的、被忽视的错误?非常感谢您的任何建议!
js文件来源:
$(function(){
// Remove the coda-slider-no-js class from the body
$("body").removeClass("coda-slider-no-js");
// Preloader
$(".coda-slider").children('.panel').hide().end().prepend('<p class="loading">Loading...<br /><img src="images/ajax-loader.gif" alt="loading..." /></p>');
});
var sliderCount = 1;
$.fn.codaSlider = function(settings) {
settings = $.extend({
autoHeight: true,
autoHeightEaseDuration: 1000,
autoHeightEaseFunction: "easeInOutExpo",
autoSlide: false,
autoSlideInterval: 7000,
autoSlideStopWhenClicked: true,
crossLinking: true,
dynamicArrows: true,
dynamicArrowLeftText: "« left",
dynamicArrowRightText: "right »",
dynamicTabs: true,
dynamicTabsAlign: "center",
dynamicTabsPosition: "top",
externalTriggerSelector: "a.xtrig",
firstPanelToLoad: 1,
panelTitleSelector: "h2.title",
slideEaseDuration: 1000,
slideEaseFunction: "easeInOutExpo"
}, settings);
return this.each(function(){
var slider = $(this);
var panelCount = slider.find(".panel").size();
var panelWidth = 100;
var panelContainerWidth = "400%";
var navClicks = 0; // Used if autoSlideStopWhenClicked = true
// Surround the collection of panel divs with a container div (wide enough for all panels to be lined up end-to-end)
$('.panel', slider).wrapAll('<div class="panel-container"></div>');
// Specify the width of the container div (wide enough for all panels to be lined up end-to-end)
$(".panel-container", slider).css({ width: panelContainerWidth });
// Specify the current panel.
// If the loaded URL has a hash (cross-linking), we're going to use that hash to give the slider a specific starting position...
if (settings.crossLinking && location.hash && parseInt(location.hash.slice(1)) <= panelCount) {
var currentPanel = parseInt(location.hash.slice(1));
var offset = - (panelWidth*(currentPanel - 1)) + "%";
$('.panel-container', slider).css({ marginLeft: offset });
// If that's not the case, check to see if we're supposed to load a panel other than Panel 1 initially...
} else if (settings.firstPanelToLoad != 1 && settings.firstPanelToLoad <= panelCount) {
var currentPanel = settings.firstPanelToLoad;
var offset = - (panelWidth*(currentPanel - 1)) + "%";
$('.panel-container', slider).css({ marginLeft: offset });
// Otherwise, we'll just set the current panel to 1...
} else {
var currentPanel = 1;
};
// If we need a dynamic menu
if (settings.dynamicTabs) {
var dynamicTabs = '<div class="coda-nav" id="coda-nav-' + sliderCount + '"><ul></ul></div>';
switch (settings.dynamicTabsPosition) {
case "bottom":
slider.parent().append(dynamicTabs);
break;
default:
slider.parent().prepend(dynamicTabs);
break;
};
ul = $('#coda-nav-' + sliderCount + ' ul');
// Create the nav items
$('.panel', slider).each(function(n) {
ul.append('<li class="tab' + (n+1) + '"><a href="#' + (n+1) + '">' + $(this).find(settings.panelTitleSelector).text() + '</a></li>');
});
navContainerWidth = slider.width() + slider.siblings('.coda-nav-left').width() + slider.siblings('.coda-nav-right').width();
ul.parent().css({ width: navContainerWidth });
switch (settings.dynamicTabsAlign) {
case "center":
ul.css({ width: ($("li", ul).width() + 2) * panelCount });
break;
case "right":
ul.css({ float: 'right' });
break;
};
};
// If we need a tabbed nav
$('#coda-nav-' + sliderCount + ' a').each(function(z) {
// What happens when a nav link is clicked
$(this).bind("click", function() {
navClicks++;
$(this).addClass('current').parents('ul').find('a').not($(this)).removeClass('current');
if (z == 0) {
offset = "+0px";
} else {
offset = - (panelWidth*z) + "%";
}
alert("Offset = " + offset);
// alterPanelHeight(z);
currentPanel = z + 1;
$('.panel-container', slider).animate({ marginLeft: offset }, settings.slideEaseDuration, settings.slideEaseFunction);
if (!settings.crossLinking) { return false }; // Don't change the URL hash unless cross-linking is specified
});
});
// Specify which tab is initially set to "current". Depends on if the loaded URL had a hash or not (cross-linking).
if (settings.crossLinking && location.hash && parseInt(location.hash.slice(1)) <= panelCount) {
$("#coda-nav-" + sliderCount + " a:eq(" + (location.hash.slice(1) - 1) + ")").addClass("current");
// If there's no cross-linking, check to see if we're supposed to load a panel other than Panel 1 initially...
} else if (settings.firstPanelToLoad != 1 && settings.firstPanelToLoad <= panelCount) {
$("#coda-nav-" + sliderCount + " a:eq(" + (settings.firstPanelToLoad - 1) + ")").addClass("current");
// Otherwise we must be loading Panel 1, so make the first tab the current one.
} else {
$("#coda-nav-" + sliderCount + " a:eq(0)").addClass("current");
};
// Kill the preloader
$('.panel', slider).show().end().find("p.loading").remove();
slider.removeClass("preload");
sliderCount++;
});
};发布于 2011-03-11 06:05:15
你为什么要用jQuery 1.3.2,它已经有2年多的历史了?对于一个不到5年历史的图书馆来说,这是一个很大的数字。
您在使用当前稳定版本的jQuery 1.5.1时是否也遇到了同样的问题?
您确定IE使用标准模式和最新的呈现引擎来呈现您的页面吗?
使用这个meta标签:
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />看看使用最新稳定版本的jQuery是否也有同样的问题。自1.3版本以来,它发生了很大的变化。
https://stackoverflow.com/questions/5266201
复制相似问题