当我包含Bootstrap所需的jquery.js脚本时,JQuery Cycle Plugin停止工作

时间:2013-11-14 15:14:13

标签: javascript jquery html twitter-bootstrap slideshow

我一直在尝试重新创建显示here的jQuery Cycle插件。我也在使用bootstrap 3.如果我删除行<script type="text/javascript" src="static/js/jquery.js"></script>然后它可以工作,但是,我需要这个用于我的响应式导航栏,并且真的不知道它为什么这样做。以下是源代码:实时页面为here。我已经尝试了几个小时才能得到这个并刚刚碰壁砖。

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">



<!-- Bootstrap -->
<link rel="stylesheet" type="text/css" href="static/css/bootstrap.css" />
<link href="static/css/bootstrap-theme.css" rel="stylesheet">
<link href="static/css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="static/css/bootstrap-theme.min.css" rel="stylesheet" media="screen">

<link rel="stylesheet" type="text/css" href="static/css/style.css"> 

<link rel="shortcut icon" href="./static/images/favicon.ico" type="image/x-icon">
<link rel="icon" href="./static/images/favicon.ico" type="image/x-icon"><title>JQuery Cycle Plugin - Basic Demo</title>
<style type="text/css">
.slideshow { height: 232px; width: 232px; margin: auto }
.slideshow img { padding: 15px; border: 1px solid #ccc; background-color: #eee; }
</style>
<!-- include jQuery library -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<!-- include Cycle plugin -->
<script type="text/javascript" src="http://malsup.github.com/jquery.cycle.all.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $('.slideshow').cycle({
        fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
    });
});
</script>
</head>
<header class="navbar navbar-inverse navbar-fixed-top bs-docs-nav" role="banner">
    <div class="container">
        <div class="navbar-header">
            <button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".bs-navbar-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            </button>
            <a id="nav-home" href="./index.html" class="navbar-brand">Home</a>
        </div>
        <nav class="collapse navbar-collapse bs-navbar-collapse" role="navigation">
            <ul class="nav navbar-nav">

                <li id="nav-resume"><a id="link" href="resume.html">Resume</a></li>
                <li id="nav-projects"><a id="link" href="portfolio.php">Portfolio</a></li>
                <li id="nav-contact"><a id="link" href="contact.html">Contact Me</a></li>

            </ul>
        </nav>
    </div>
</header>
<div id="wrap">
<div class="container">
<!--container is ended in footer tag.--><body>
    <div class="slideshow">
        <img src="http://malsup.github.com/images/beach1.jpg" width="200" height="200" />
        <img src="http://malsup.github.com/images/beach2.jpg" width="200" height="200" />
        <img src="http://malsup.github.com/images/beach3.jpg" width="200" height="200" />
        <img src="http://malsup.github.com/images/beach4.jpg" width="200" height="200" />
        <img src="http://malsup.github.com/images/beach5.jpg" width="200" height="200" />
    </div>

    </div>
</div>
<!--
<div id="footer">
    <div class="container">
        <p1 class="text-muted credit">&copy; 2013 michaelwashburnjr.com</p1>
    </div>
</div>
-->

<!-- Includes -->
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script type="text/javascript" src="static/js/jquery.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script type="text/javascript" src="static/js/bootstrap.min.js"></script>
</body>
</html>

[编辑]我现在使用的是<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>而不是<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>并且遇到了同样的错误。

2 个答案:

答案 0 :(得分:2)

你加载的jQuery文件很旧,Bootstrap需要更高版本查看他们的bower包"jquery": ">= 1.9.0"

https://developers.google.com/speed/libraries/devguide#jquery

答案 1 :(得分:2)

你以一种破坏循环插件的方式包含jQuery两次。你有:

<!-- include jQuery library --> // FIRST INCLUDE
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<!-- include Cycle plugin -->
<script type="text/javascript" src="http://malsup.github.com/jquery.cycle.all.js"></script>

...

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> // SECOND INCLUDE
<script type="text/javascript" src="static/js/jquery.js"></script>

您应该将所有脚本移到底部,并将其包括在内:

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script type="text/javascript" src="static/js/jquery.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script type="text/javascript" src="static/js/bootstrap.min.js"></script>

<!-- include Cycle plugin -->
<script type="text/javascript" src="http://malsup.github.com/jquery.cycle.all.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $('.slideshow').cycle({
        fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
    });
});
</script>

这样你的第二个jQuery副本就不会破坏用第一个副本注册的插件。