嗨,所有一些noobie jquery问题与codaslider我是无数的。
我正在尝试将codaslider添加到我正在处理的页面中,即使在http://www.ndoherty.biz/demos/coda-slider/2.0/#1处遵循示例后,我在尝试显示滑块时遇到错误。
我在Firebug中遇到以下错误:
$("#coda-slider-1").codaSlider is not a function
http://localhost/js/ui/landingpage_ui.js
Line 10
当文档加载时,这个javascript代码在onload命令中完成:
function load(){
$().ready(function() {
$('#coda-slider-1').codaSlider({
dynamicArrows: false,
dynamicTabs: false
});
});
}
javascript全部由Zend Framework视图处理,所以实际的html / php文档如下所示:
<?php
$this->headScript()->appendFile($this->baseUrl() . '/js/jquery.coda-slider-2.0.js', 'text/javascript');
$this->headScript()->appendFile($this->baseUrl() . '/js/jquery.easing.1.3.js', 'text/javascript');
$this->headLink()->prependStylesheet($this->baseUrl() . '/css/coda-slider-2.0.css');
$this->headLink()->prependStylesheet($this->baseUrl() . '/css/reset.css');
$this->headScript()->appendFile($this->baseUrl() . '/js/ui/landingpage_ui.js', 'text/javascript');
$this->layout()->bodyScripts = "onload='load()'";
?>
<div class="coda-slider-wrapper">
<div id="coda-nav-left-1" class="coda-nav-left"><a href="#" title="Slide left">«</a></div>
<div id="coda-nav-1" class="coda-nav">
<ul>
<li class="tab1"><a href="#1">Panel 1</a></li>
<li class="tab2"><a href="#2">Panel 2</a></li>
<li class="tab3"><a href="#3">Panel 3</a></li>
<li class="tab4"><a href="#4">Panel 4</a></li>
</ul>
</div>
<div id="coda-nav-right-1" class="coda-nav-right"><a href="#" title="Slide right">»</a></div>
<div class="coda-slider preload" id="coda-slider-1">
<div class="panel">
<div class="panel-wrapper">
<h2 class="title">Panel 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas metus nulla, commodo a sodales sed, dignissim pretium nunc. Nam et lacus neque. Sed volutpat ante id mauris laoreet vestibulum. Nam blandit felis non neque cursus aliquet. Morbi vel enim dignissim massa dignissim commodo vitae quis tellus. Nunc non mollis nulla. Sed consectetur elit id mi consectetur bibendum. Ut enim massa, sodales tempor convallis et, iaculis ac massa. Etiam suscipit nisl eget lorem pellentesque quis iaculis mi mattis. Aliquam sit amet purus lectus. Maecenas tempor ornare sollicitudin.</p>
</div>
</div>
<div class="panel">
<div class="panel-wrapper">
<h2 class="title">Panel 2</h2>
<p>Proin nec turpis eget dolor dictum lacinia. Nullam nunc magna, tincidunt eu porta in, faucibus sed magna. Suspendisse laoreet ornare ullamcorper. Nulla in tortor nibh. Pellentesque sed est vitae odio vestibulum aliquet in nec leo.</p>
</div>
</div>
<div class="panel">
<div class="panel-wrapper">
<h2 class="title">Panel 3</h2>
<p>Cras luctus fringilla odio vel hendrerit. Cras pulvinar auctor sollicitudin. Sed lacus quam, sodales sit amet feugiat sit amet, viverra nec augue. Sed enim ipsum, malesuada quis blandit vel, posuere eget erat. Sed a arcu justo. Integer ultricies, nunc at lobortis facilisis, ligula lacus vestibulum quam, id tincidunt sapien arcu in velit. Vestibulum consequat augue et turpis condimentum mollis sed vitae metus. Morbi leo libero, tincidunt lobortis fermentum eget, rhoncus vel sem. Morbi varius viverra velit vel tempus. Morbi enim turpis, facilisis vel volutpat at, condimentum quis erat. Morbi auctor rutrum libero sed placerat. Etiam ipsum velit, eleifend in vehicula eu, tristique a ipsum. Donec vitae quam vel diam iaculis bibendum eget ut diam. Fusce quis interdum diam. Ut urna justo, dapibus a tempus sit amet, bibendum at lectus. Sed venenatis molestie commodo.</p>
</div>
</div>
<div class="panel">
<div class="panel-wrapper">
<h2 class="title">Panel 4</h2>
<p>Nulla ultricies ornare erat, a rutrum lacus varius nec. Pellentesque vehicula lobortis dignissim. Ut scelerisque auctor eros sed porttitor. Nullam pulvinar ultrices malesuada. Quisque lobortis bibendum nisi et condimentum. Mauris quis erat vel dui lobortis dignissim.</p>
</div>
</div>
</div><!-- .coda-slider -->
</div><!-- .coda-slider-wrapper -->
我正在使用codaslider库的2.0版和jQuery主库的1.4.4版。
导致脚本无法加载和执行的原因是什么?当我查看生成的页面源时,一切似乎都在那里并加载。
非常感谢。
捐赠
答案 0 :(得分:1)
如果codaSlider
插件基于easing
插件,则需要先包含easing
。所以只需尝试更改顺序:
$this->headScript()->appendFile($this->baseUrl() . '/js/jquery.easing.1.3.js', 'text/javascript');
$this->headScript()->appendFile($this->baseUrl() . '/js/jquery.coda-slider-2.0.js', 'text/javascript');
并且不要忘记首先添加jquery
,因此我建议始终prependFile()
使用jquery
:
$this->headScript()->prependFile($this->baseUrl() . '/js/jquery-1.4.2.min.js', 'text/javascript');