Jquery 推特引导旋转木马:右&;左箭头不起作用
BS转盘的箭头未前后移动项目Jquery 推特引导旋转木马:右&;左箭头不起作用,jquery,css,twitter-bootstrap,Jquery,Css,Twitter Bootstrap,BS转盘的箭头未前后移动项目 我怀疑这可能是一个CSS问题,或者与轮播正在标签中使用的事实有关 您需要在jQuery之后包含boostrap.js才能使其正常工作。我还发现指向jQuery的链接有一个错误: <script type='text/javascript' src='/ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js'></script> 应该是 <script type='text
我怀疑这可能是一个CSS问题,或者与轮播正在标签中使用的事实有关 您需要在jQuery之后包含boostrap.js才能使其正常工作。我还发现指向jQuery的链接有一个错误:
<script type='text/javascript' src='/ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js'></script>
应该是
<script type='text/javascript' src='//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js'></script>
您的HTML格式是这样的吗
<div id="myCarousel" class="carousel slide">
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<!-- Carousel items -->
<div class="carousel-inner">
<div class="active item">…</div>
<div class="item">…</div>
<div class="item">…</div>
</div>
<!-- Carousel nav -->
<a class="carousel-control left" href="#myCarousel" data-slide="prev">‹</a>
<a class="carousel-control right" href="#myCarousel" data-slide="next">›</a>
</div>
…
…
…
希望有帮助 引导依赖于jQuery。查看他们的。将JQ和bootstrap.min.js放在页面底部,如下所示:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
请记住,您需要一个与您的引导版本配合使用的JQ版本。我使用的是bootstrap版本2,所以我需要JQ 1.11.1我也遇到了同样的问题,这是因为我的页面是基于滚动的,所以我加入了一个小脚本来平滑从
开始的每个链接的滚动。这拧坏了左右按钮,因为它们使用href=“#myCarousel”
为了解决这个问题,我在脚本中添加了一个异常,如下所示。
这是我修改之前的脚本:
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
我刚刚添加了一个带有thw href属性的异常:
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if( $(this).attr("href")=="#myCarousel") return;//This is the exception
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
这个答案迟了一年半,但我希望它能帮助其他人
2015年3月12日编辑:您也可以使用
数据目标
属性,而不是href
我的旋转木马也不工作,我改变了很多事情。但是最后我发现了问题;我的问题是平滑滚动和wow.js。事实上,由于平滑滚动的原因,我无法按下“上一步”或“下一步”按钮。当我试着按下按钮时,页面向下或向上移动。因此,我改变了我的平滑初始化和哇初始化这样
平滑滚动:
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if( $(this).attr("href")=="#CarouselSlider") return;
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 900);
return false;
}
}
});
}))
还有Wow.js init:
$(document).ready(
function() {
$("html").niceScroll({
cursorcolor:"#ba8e16",
scrollspeed :"100",
cursorborder:"1px solid #cf9c11",
horizrailenabled: "false",
cursorborderradius: "0px"
});
}
));
新的WOW().init()
现在,水平平滑结束了,我的问题不知怎么消失了。我希望,这会有帮助。同样的事情也发生在我身上。事实证明,在jquery脚本之前,我刚刚在上安装了引导脚本。改变了这一点,然后工作正常。Bootstrap JS是。无法加载jQuery文件是另一个问题,但如果不是从Google加载jQuery,则会加载另一个jQuery。您是否初始化了carroussel$(“#meet_team_carousel”).carousel()?我认为不必初始化它。“旋转木马”类也会做同样的事情。正如我所提到的,圆形白色圆圈(右上角)正在工作并正确地导航项目。似乎引导本身没有启动,因为如果您试图通过控制台激活它,它会显示“TypeError:Object[Object Object]没有方法‘carousel’”。也许你可能有一个javascript错误阻止了它。先生,你是一个黄金神。晚了一年半,但对我来说很有魅力,我使用了与您完全相同的代码来平滑滚动:)非常感谢您添加了您的答案。我有一个同样的问题,现在它消失了-感谢你。太棒了,我有同样的平滑滚动代码和同样的问题。谢谢“您也可以使用数据目标属性,而不是href”…是的,这在Bootstrap 3中为我做到了:)