javascript在I.E.中无效9以及Firefox

时间:2013-11-17 19:24:29

标签: javascript jquery html css jquery-animate

问候stackoverflow成员,

我最近陷入了困境。下面提供的代码非常冗长,但是,大多数代码都是标记为(General,Kills和Scores)的每3个主要容器的重复代码。

我遇到了与jquery 1.9.1一致的javascript问题 - 滑块没有滑动 - 它在Chrome中完美运行,但由于某些原因不适用于IE9以及Firefox。 ..我已经无数次修改了它,但是没有看到为什么它不适用于那些浏览器的问题。如果你可以查看它并在我的javascript中向我提供我出错的地方或地点,我会非常感激它,因为我认为你们/ gals更容易发现问题,因为它对你的眼睛很新鲜

DEMO:http://jsfiddle.net/aeJtx/3/

JAVASCRIPT:

/* ===== Start of 'Slider - My Statistics (Achievements - General)' ===== */
$(function () {
    $('input.field').focus(function () {
        if (this.title == this.value) {
            this.value = '';
        }
    }).blur(function () {
        if (this.value === '') {
            this.value = this.title;
        }
    });
    var currentPage = 1;
    $('#slider_achievements_general .buttons_achievements_general span').on('click', function () {
        var timeout = setTimeout(function () {
            $("img").trigger("slidermove");
        }, 100);
        var fragments_count = $(this).parents('#slider_achievements_general:eq(0)').find('.fragment_achievements_general').length;
        var fragment_width = $(this).parents('#slider_achievements_general:eq(0)').find('.fragment_achievements_general').width();
        var perPage = 1;
        var numPages = Math.ceil(fragments_count / perPage);
        var stepMove = fragment_width * perPage;
        var container = $(this).parents('#slider_achievements_general:eq(0)').find('.con_achievements_general');
        var firstPosition = 0;
        var lastPosition = -((numPages - 1) * stepMove);
        if ($(this).hasClass('next')) {
            currentPage++;
            if (currentPage > numPages) {
                currentPage = 1;
                container.animate({
                    'left': firstPosition
                });
                return;
            }
            container.animate({
                'left': -((currentPage - 1) * stepMove)
            });
        }
        if ($(this).hasClass('prev')) {
            currentPage--;
            if (currentPage < 1) {
                currentPage = numPages;
                container.animate({
                    'left': lastPosition
                });
                return;
            }
            container.animate({
                'left': -((currentPage - 1) * stepMove)
            });
        }
    });
});

/* ===== Start of 'Slider - My Statistics (Achievements - Kills)' ===== */
$(function () {
    $('input.field').focus(function () {
        if (this.title == this.value) {
            this.value = '';
        }
    }).blur(function () {
        if (this.value === '') {
            this.value = this.title;
        }
    });
    var currentPage = 1;
    $('#slider_achievements_kills .buttons_achievements_kills span').on('click', function () {
        var timeout = setTimeout(function () {
            $("img").trigger("slidermove");
        }, 100);
        var fragments_count = $(this).parents('#slider_achievements_kills:eq(0)').find('.fragment_achievements_kills').length;
        var fragment_width = $(this).parents('#slider_achievements_kills:eq(0)').find('.fragment_achievements_kills').width();
        var perPage = 1;
        var numPages = Math.ceil(fragments_count / perPage);
        var stepMove = fragment_width * perPage;
        var container = $(this).parents('#slider_achievements_kills:eq(0)').find('.con_achievements_kills');
        var firstPosition = 0;
        var lastPosition = -((numPages - 1) * stepMove);
        if ($(this).hasClass('next')) {
            currentPage++;
            if (currentPage > numPages) {
                currentPage = 1;
                container.animate({
                    'left': firstPosition
                });
                return;
            }
            container.animate({
                'left': -((currentPage - 1) * stepMove)
            });
        }
        if ($(this).hasClass('prev')) {
            currentPage--;
            if (currentPage < 1) {
                currentPage = numPages;
                container.animate({
                    'left': lastPosition
                });
                return;
            }
            container.animate({
                'left': -((currentPage - 1) * stepMove)
            });
        }
    });
});

/* ===== Start of 'Slider - My Statistics (Achievements - Scores)' ===== */
$(function () {
    $('input.field').focus(function () {
        if (this.title == this.value) {
            this.value = '';
        }
    }).blur(function () {
        if (this.value === '') {
            this.value = this.title;
        }
    });
    var currentPage = 1;
    $('#slider_achievements_scores .buttons_achievements_scores span').on('click', function () {
        var timeout = setTimeout(function () {
            $("img").trigger("slidermove");
        }, 100);
        var fragments_count = $(this).parents('#slider_achievements_scores:eq(0)').find('.fragment_achievements_scores').length;
        var fragment_width = $(this).parents('#slider_achievements_scores:eq(0)').find('.fragment_achievements_scores').width();
        var perPage = 1;
        var numPages = Math.ceil(fragments_count / perPage);
        var stepMove = fragment_width * perPage;
        var container = $(this).parents('#slider_achievements_scores:eq(0)').find('.con_achievements_scores');
        var firstPosition = 0;
        var lastPosition = -((numPages - 1) * stepMove);
        if ($(this).hasClass('next')) {
            currentPage++;
            if (currentPage > numPages) {
                currentPage = 1;
                container.animate({
                    'left': firstPosition
                });
                return;
            }
            container.animate({
                'left': -((currentPage - 1) * stepMove)
            });
        }
        if ($(this).hasClass('prev')) {
            currentPage--;
            if (currentPage < 1) {
                currentPage = numPages;
                container.animate({
                    'left': lastPosition
                });
                return;
            }
            container.animate({
                'left': -((currentPage - 1) * stepMove)
            });
        }
    });
});

CSS:

/* ===== Start of 'Achievement Details - (General)' ===== */
 #general_wrapper {
    width: 650px;
    height: 150px;
    padding: 0;
    margin: 0 auto;
    background: #333;
    border: 2px solid #444;
    -moz-border-radius: 12px;
    -webkit-border-radius: 12px;
    border-radius: 12px;
    -moz-box-shadow: 0 28px 24px -24px #000, inset 0 -0.3em 0.9em 0.3em #000;
    -webkit-box-shadow: 0 28px 24px -24px #000, inset 0 -0.3em 0.9em 0.3em #000;
    box-shadow: 0 28px 24px -24px #000, inset 0 -0.3em 0.9em 0.3em #000;
    position: relative;
    top: 20px;
}
#general_wrapper h2 {
    width: 626px;
    height: 20px;
    padding: 6px 0 6px 0;
    margin: 0 12px;
    border-bottom: 1px solid #444;
    float: left;
    color: #AB9B68;
    font: 20px Arial, Helvetica, sans-serif;
    font-weight: bold;
    font-variant: small-caps;
    text-shadow: 1px 1px 1px #000, -2px -2px 2px #000;
    filter: progid:DXImageTransform.Microsoft.Shadow(direction=315, strength=2, color=000000);
}
#slider_achievements_general {
    width: 577px;
    height: 96px;
    padding: 0;
    margin: 0 auto;
    background: #222;
    border: 2px solid #444;
    -moz-box-shadow: inset 0 0.3em 0.9em 0.3em #000;
    -webkit-box-shadow: inset 0 0.3em 0.9em 0.3em #000;
    box-shadow: inset 0 0.3em 0.9em 0.3em #000;
    position: relative;
    top: 40px;
}
.buttons_achievements_general {
    position: absolute;
    top: -2px;
    right: -25px;
    z-index: 101;
}
.buttons_achievements_general span {
    position: absolute;
    display: block;
    width: 22px;
    height: 62px;
    padding: 34px 0 0 0;
    cursor: pointer;
}
.buttons_achievements_general span.prev {
    color: #111;
    font: 20px Arial, Helvetica, sans-serif;
    font-weight: bold;
    right: 602px;
    background: rgba(204, 204, 204, 0.5);
    border: 2px solid #444;
    -moz-border-radius: 8px 0 0 8px;
    -webkit-border-radius: 8px 0 0 8px;
    border-radius: 8px 0 0 8px;
    -moz-box-shadow: inset 0 -0.15em 0.45em 0.15em #000;
    -webkit-box-shadow: inset 0 -0.15em 0.45em 0.15em #000;
    box-shadow: inset 0 -0.15em 0.45em 0.15em #000;
    text-align: center;
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.7);
}
.buttons_achievements_general span.next {
    color: #111;
    font: 20px Arial, Helvetica, sans-serif;
    font-weight: bold;
    right: 0;
    background: rgba(204, 204, 204, 0.5);
    border: 2px solid #444;
    -moz-border-radius: 0 8px 8px 0;
    -webkit-border-radius: 0 8px 8px 0;
    border-radius: 0 8px 8px 0;
    -moz-box-shadow: inset 0 -0.15em 0.45em 0.15em #000;
    -webkit-box-shadow: inset 0 -0.15em 0.45em 0.15em #000;
    box-shadow: inset 0 -0.15em 0.45em 0.15em #000;
    text-align: center;
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.7);
}
.holder_achievements_general {
    width: 577px;
    height: 96px;
    position: relative;
    top: -31px;
    overflow: hidden;
}
.con_achievements_general {
    width: 100000px;
    height: 96px;
    position: absolute;
}
.fragment_achievements_general {
    width: 577px;
    height: 96px;
    float: left;
    display: inline;
}
/* ===== Start of 'General Medals Wrapper inside Fragment' ===== */
 #general_medals_wrapper {
    width: 576px;
    height: 96px;
    float: left;
}
/* ===== Start of 'Achievement Details - (Kills)' ===== */
 #kills_wrapper {
    width: 650px;
    height: 150px;
    padding: 0;
    margin: 0 auto;
    background: #333;
    border: 2px solid #444;
    -moz-border-radius: 12px;
    -webkit-border-radius: 12px;
    border-radius: 12px;
    -moz-box-shadow: 0 28px 24px -24px #000, inset 0 -0.3em 0.9em 0.3em #000;
    -webkit-box-shadow: 0 28px 24px -24px #000, inset 0 -0.3em 0.9em 0.3em #000;
    box-shadow: 0 28px 24px -24px #000, inset 0 -0.3em 0.9em 0.3em #000;
    position: relative;
    top: 50px;
}
#kills_wrapper h2 {
    width: 626px;
    height: 20px;
    padding: 6px 0 6px 0;
    margin: 0 12px;
    border-bottom: 1px solid #444;
    float: left;
    color: #AB9B68;
    font: 20px Arial, Helvetica, sans-serif;
    font-weight: bold;
    font-variant: small-caps;
    text-shadow: 1px 1px 1px #000, -2px -2px 2px #000;
    filter: progid:DXImageTransform.Microsoft.Shadow(direction=315, strength=2, color=000000);
}
#slider_achievements_kills {
    width: 577px;
    height: 96px;
    padding: 0;
    margin: 0 auto;
    background: #222;
    border: 2px solid #444;
    -moz-box-shadow: inset 0 0.3em 0.9em 0.3em #000;
    -webkit-box-shadow: inset 0 0.3em 0.9em 0.3em #000;
    box-shadow: inset 0 0.3em 0.9em 0.3em #000;
    position: relative;
    top: 40px;
}
.buttons_achievements_kills {
    position: absolute;
    top: -2px;
    right: -25px;
    z-index: 101;
}
.buttons_achievements_kills span {
    position: absolute;
    display: block;
    width: 22px;
    height: 62px;
    padding: 34px 0 0 0;
    cursor: pointer;
}
.buttons_achievements_kills span.prev {
    color: #111;
    font: 20px Arial, Helvetica, sans-serif;
    font-weight: bold;
    right: 602px;
    background: rgba(204, 204, 204, 0.5);
    border: 2px solid #444;
    -moz-border-radius: 8px 0 0 8px;
    -webkit-border-radius: 8px 0 0 8px;
    border-radius: 8px 0 0 8px;
    -moz-box-shadow: inset 0 -0.15em 0.45em 0.15em #000;
    -webkit-box-shadow: inset 0 -0.15em 0.45em 0.15em #000;
    box-shadow: inset 0 -0.15em 0.45em 0.15em #000;
    text-align: center;
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.7);
}
.buttons_achievements_kills span.next {
    color: #111;
    font: 20px Arial, Helvetica, sans-serif;
    font-weight: bold;
    right: 0;
    background: rgba(204, 204, 204, 0.5);
    border: 2px solid #444;
    -moz-border-radius: 0 8px 8px 0;
    -webkit-border-radius: 0 8px 8px 0;
    border-radius: 0 8px 8px 0;
    -moz-box-shadow: inset 0 -0.15em 0.45em 0.15em #000;
    -webkit-box-shadow: inset 0 -0.15em 0.45em 0.15em #000;
    box-shadow: inset 0 -0.15em 0.45em 0.15em #000;
    text-align: center;
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.7);
}
.holder_achievements_kills {
    width: 577px;
    height: 96px;
    padding: 0;
    margin: 0;
    position: relative;
    top: -31px;
    overflow: hidden;
}
.con_achievements_kills {
    width: 100000px;
    height: 96px;
    position: absolute;
}
.fragment_achievements_kills {
    width: 577px;
    height: 96px;
    float: left;
    display: inline;
}
/* ===== Start of 'Kills Medals Wrapper inside Fragment' ===== */
 #kills_medals_wrapper {
    width: 650px;
    height: 150px;
    float: left;
}
/* ===== Start of 'Achievement Details - (Scores)' ===== */
 #scores_wrapper {
    width: 650px;
    height: 150px;
    padding: 0;
    margin: 0 auto;
    background: #333;
    border: 2px solid #444;
    -moz-border-radius: 12px;
    -webkit-border-radius: 12px;
    border-radius: 12px;
    -moz-box-shadow: 0 28px 24px -24px #000, inset 0 -0.3em 0.9em 0.3em #000;
    -webkit-box-shadow: 0 28px 24px -24px #000, inset 0 -0.3em 0.9em 0.3em #000;
    box-shadow: 0 28px 24px -24px #000, inset 0 -0.3em 0.9em 0.3em #000;
    position: relative;
    top: 80px;
}
#scores_wrapper h2 {
    width: 626px;
    height: 20px;
    padding: 6px 0 6px 0;
    margin: 0 12px;
    border-bottom: 1px solid #444;
    float: left;
    color: #AB9B68;
    font: 20px Arial, Helvetica, sans-serif;
    font-weight: bold;
    font-variant: small-caps;
    text-shadow: 1px 1px 1px #000, -2px -2px 2px #000;
    filter: progid:DXImageTransform.Microsoft.Shadow(direction=315, strength=2, color=000000);
}
#slider_achievements_scores {
    width: 577px;
    height: 96px;
    padding: 0;
    margin: 0 auto;
    background: #222;
    border: 2px solid #444;
    -moz-box-shadow: inset 0 0.3em 0.9em 0.3em #000;
    -webkit-box-shadow: inset 0 0.3em 0.9em 0.3em #000;
    box-shadow: inset 0 0.3em 0.9em 0.3em #000;
    position: relative;
    top: 40px;
}
.buttons_achievements_scores {
    position: absolute;
    top: -2px;
    right: -25px;
    z-index: 101;
}
.buttons_achievements_scores span {
    position: absolute;
    display: block;
    width: 22px;
    height: 62px;
    padding: 34px 0 0 0;
    cursor: pointer;
}
.buttons_achievements_scores span.prev {
    color: #111;
    font: 20px Arial, Helvetica, sans-serif;
    font-weight: bold;
    right: 602px;
    background: rgba(204, 204, 204, 0.5);
    border: 2px solid #444;
    -moz-border-radius: 8px 0 0 8px;
    -webkit-border-radius: 8px 0 0 8px;
    border-radius: 8px 0 0 8px;
    -moz-box-shadow: inset 0 -0.15em 0.45em 0.15em #000;
    -webkit-box-shadow: inset 0 -0.15em 0.45em 0.15em #000;
    box-shadow: inset 0 -0.15em 0.45em 0.15em #000;
    text-align: center;
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.7);
}
.buttons_achievements_scores span.next {
    color: #111;
    font: 20px Arial, Helvetica, sans-serif;
    font-weight: bold;
    right: 0;
    background: rgba(204, 204, 204, 0.5);
    border: 2px solid #444;
    -moz-border-radius: 0 8px 8px 0;
    -webkit-border-radius: 0 8px 8px 0;
    border-radius: 0 8px 8px 0;
    -moz-box-shadow: inset 0 -0.15em 0.45em 0.15em #000;
    -webkit-box-shadow: inset 0 -0.15em 0.45em 0.15em #000;
    box-shadow: inset 0 -0.15em 0.45em 0.15em #000;
    text-align: center;
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.7);
}
.holder_achievements_scores {
    width: 577px;
    height: 96px;
    padding: 0;
    margin: 0;
    position: relative;
    top: -31px;
    overflow: hidden;
}
.con_achievements_scores {
    width: 100000px;
    height: 96px;
    position: absolute;
}
.fragment_achievements_scores {
    width: 577px;
    height: 96px;
    float: left;
    display: inline;
}
/* ===== Start of 'Kills Medals Wrapper inside Fragment' ===== */
 #scores_medals_wrapper {
    width: 650px;
    height: 150px;
    float: left;
}

HTML:

<div id="general_wrapper">
     <h2>General</h2>

    <div id="slider_achievements_general">
        <div class="buttons_achievements_general"> <span class="next" title="Next">»</span>  <span class="prev" title="Previous">«</span>

        </div>
        <div class="holder_achievements_general">
            <div class="con_achievements_general">
                <div class="fragment_achievements_general">
                    <div id="general_medals_wrapper">
                        <p>Hi</p>
                    </div>
                </div>
                <div class="fragment_achievements_general">
                    <div id="general_medals_wrapper">
                        <p>World</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="kills_wrapper">
     <h2>Kills</h2>

    <div id="slider_achievements_kills">
        <div class="buttons_achievements_kills"> <span class="next" title="Next">»</span>  <span class="prev" title="Previous">«</span>

        </div>
        <div class="holder_achievements_kills">
            <div class="con_achievements_kills">
                <div class="fragment_achievements_kills">
                    <div id="kills_medals_wrapper">
                        <p>Hello</p>
                    </div>
                </div>
                <div class="fragment_achievements_kills">
                    <div id="kills_medals_wrapper">
                        <p>World</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="scores_wrapper">
     <h2>Scores</h2>

    <div id="slider_achievements_scores">
        <div class="buttons_achievements_scores"> <span class="next" title="Next">»</span>  <span class="prev" title="Previous">«</span>

        </div>
        <div class="holder_achievements_scores">
            <div class="con_achievements_scores">
                <div class="fragment_achievements_scores">
                    <div id="scores_medals_wrapper">
                        <p>New</p>
                    </div>
                </div>
                <div class="fragment_achievements_scores">
                    <div id="scores_medals_wrapper">
                        <p>Slider</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

1 个答案:

答案 0 :(得分:1)

我相信我可以解决这个问题。我最后在不同的脚本上将上面的代码添加到我的网站,以查看问题的位置,并认为这可能是你在FF或IE中无法正常工作的问题 - 因为它碰巧我和过去一样,当我实现上面的代码时,它确实做了同样的事情。

如果您有多个js页面位于不同的文件夹/目录中,请检查您的html页面如何引用您的javascript页面。

例如,请执行此操作:

<script type="text/javascript" src="/js/JQuery/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="js/Your_Script.js"></script>
<script type="text/javascript" src="/js/My_Script.js"></script>

而不是这个:

<script type="text/javascript" src="/js/JQuery/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="/js/My_Script.js"></script>
<script type="text/javascript" src="js/Your_Script.js"></script>

如果您的站点上有多个使用JS的文件夹/目录,则需要确保您正在处理的任何页面都可以检查您正在处理的页面的JS脚本,而不是您可能正在使用的任何其他JS脚本在其他文件夹/目录中。因此,如果您使用我提供给您的上面的第一个示例,它应该在所有浏览器中都没有问题。这几个月前发生在我身上,它让我永远想知道发生了什么。

你想确保你所使用的任何jquery都被写入并在所有html页面上首先被引用,那么你可能拥有的任何js脚本应该遵循这一点,但要确保它们在你的任何html页面上的顺序正确正在努力。

设置示例:

主目录:

- &GT; css文件夹

-------&GT; Your_css_Script.css

- &GT;图像文件夹

- &GT; js文件夹(在'js文件夹'里面你有:)

-------&GT; Your_js_Script.js

-------&GT; JQuery文件夹

------------&GT;的jquery-1.9.1.min.js

- &GT;的index.html

- &GT;另一个文件夹 - (在'另一个文件夹'里面):

-------&GT; css文件夹

------------&GT; Your_css2_Script.css

-------&GT;图像文件夹

-------&GT; js文件夹

------------&GT; Your_js2_Script.js

-------&GT; index2.html

我为上面的错误图表道歉,但希望这可以帮助您理解结构。因此,如果您正在处理index2.html以及Your_js2_Script.js,还需要在index2.html上引用Your_js_Script.js上的内容以及jquery脚本,那么您需要在index2.html页面如此:

<script type="text/javascript" src="/js/JQuery/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="js/Your_js2_Script.js"></script>
<script type="text/javascript" src="/js/Your_js_Script.js"></script>

顺便说一句,这是一个非常光滑的外观设置你继续!我希望我提供的帮助。