【问题标题】:Exact Same Script Works On One Page But Not Another完全相同的脚本在一个页面上有效,但在另一个页面上无效
【发布时间】:2014-05-13 14:10:17
【问题描述】:

我正在使用在此处找到的模板构建 iOS7 WebApp: http://c2prods.com/2013/cloning-the-ui-of-ios-7-with-html-css-and-javascript/

我编写了一些 JavaScript/jQuery 来淡出图片并淡入工具栏,首先是工具栏。我有一个空白测试页,我在其中测试了脚本。它完美地工作。然后我将完全相同的代码复制并粘贴到真实页面中,并且无论出于何种原因,jQuery 似乎永远不会加载。它给了我一个错误,说以下内容:

Uncaught TypeError: Object # has no method 'fadeOut'

褪色应该在 3 秒后发生。这个想法是,这是一个启动画面。

这是我的 JS/jQuery:

$(document).ready(function() {
fadeAwaySplash();
navFadeIn();
//Insert More Functions Here
});

function fadeAwaySplash() {
    //setTimeout(function() {
    $("#splash-screen").fadeOut();
    //}, 3000);
}

function navFadeIn(){
    setTimeout(function() {
    $("nav").fadeIn();
    }, 3000);
}

这是我的 CSS:

nav {
position: fixed;
bottom: 0;
width: 100%;
height: 49px;
text-align: center;
background-color: rgba(248, 248, 248, 0.9);
background-image: linear-gradient(180deg, rgb(200, 199, 204), rgb(200, 199, 204) 50%, transparent 50%);
background-size: 100% 1px;
background-repeat: no-repeat;
background-position: top center;
z-index: 100;
display: none;
}

#splash-screen {
position: absolute;
z-index: 999999;
width: 100%;
height: 100%;
min-width: 100%;
min-height: 100%;
max-width: 100%;
max-height: 100%;
}

这是我的 HTML:

<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>

<img src="/img/ipadSplash.png" id="splash-screen">

非常感谢任何帮助。

提前致谢, 伊曼纽尔

【问题讨论】:

  • 您的第二页上是否有任何可能覆盖 jQuery 的内容?您是否尝试过用 jQuery 替换 $s 以避免这种覆盖?
  • 另外我可能会建议清除所有缓存并重新加载页面。可能缓存了一些较旧的 jquery 版本。

标签: javascript jquery html css


【解决方案1】:

太棒了! scragar的回答奏效了!我所要做的就是用“jQuery”(不带引号)替换 $'s。虽然我不得不将 setTimeout 替换为 .delay(3000) 谢谢!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-20
    • 2020-08-24
    • 1970-01-01
    • 2012-08-09
    • 2022-01-14
    • 2012-08-22
    • 1970-01-01
    相关资源
    最近更新 更多