Button 平滑滚动会干扰引导3中转盘上的上一个和下一个

Button 平滑滚动会干扰引导3中转盘上的上一个和下一个,button,twitter-bootstrap-3,carousel,smooth-scrolling,Button,Twitter Bootstrap 3,Carousel,Smooth Scrolling,我最初在使用下面的JS平滑滚动时遇到了问题,因为它生成了任何真正的链接,而不是位置停止工作 $('.navbar-nav > li').click(function(event) { event.preventDefault(); var target = $(this).find('>a').prop('hash'); $('html, body').animate({ scrollTop: $(target).offset().to

我最初在使用下面的JS平滑滚动时遇到了问题,因为它生成了任何真正的链接,而不是位置停止工作

    $('.navbar-nav > li').click(function(event) {
    event.preventDefault();
    var target = $(this).find('>a').prop('hash');
    $('html, body').animate({
        scrollTop: $(target).offset().top
    }, 500);
});
所以我把它改成了

    $(document).ready(function(){
  $('a[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) {
        var targetOffset = $target.offset().top;
        $('html,body')
        .animate({scrollTop: targetOffset}, 1200);
       return false;
      }
    }
  });
});
它解决了无法在导航栏中添加可工作的“博客”链接的原始问题,但现在它已使左侧和右侧(下一个和上一个)转盘按钮不工作

如果有人能帮我解决这个问题,我将不胜感激,因为这会让我发疯

转盘的html如下所示

    <section id="main-slider" class="carousel">
    <div class="carousel-inner">
        <div class="item active">
            <div class="container">
                <div class="carousel-content">
                    <h1>Responsive Website Design</h1>
                    <p class="lead">With 20% of all website traffic in the UK coming from tablets and smart phones then never before has it been a better time to have a responsive website.</p>
                </div>
            </div>
        </div><!--/.item-->
        <div class="item">
            <div class="container">
                <div class="carousel-content">
                    <h1>Free Consultation</h1>
                    <p class="lead">I understand every business has different needs so we can discuss what it is your want to achieve and using my expert advice make it a reality.</p>
                </div>
            </div>
        </div><!--/.item-->
        <div class="item">
            <div class="container">
                <div class="carousel-content">
                    <h1>Built to be SEO/Google Friendly</h1>
                    <p class="lead">Having a website built is the first step but next you need to put it in front of your target audience. On site SEO is where it all begins.</p>
                </div>
            </div>
        </div><!--/.item-->
    </div><!--/.carousel-inner-->
    <a class="prev" href="#main-slider" data-slide="prev"><i class="icon-angle-left"></i></a>
    <a class="next" href="#main-slider" data-slide="next"><i class="icon-angle-right"></i></a>
</section><!--/#main-slider-->

响应式网站设计

在英国,20%的网站流量来自平板电脑和智能手机,因此现在是创建响应性网站的最佳时机

免费咨询

我了解每个企业都有不同的需求,因此我们可以讨论您想要实现的目标,并使用我的专家建议使之成为现实

为搜索引擎优化/谷歌友好而构建

建立一个网站是第一步,但下一步你需要把它放在目标受众面前。网站搜索引擎优化是一切开始的地方

尝试更换此:

$('a[href*=#]:非([href=#])。单击(function(){

与:

$('a[href*=#]:非([href=#媒体])。单击(函数(){

愉快的编码!

尝试替换此:

$('a[href*=#]:非([href=#])。单击(function(){

与:

$('a[href*=#]:非([href=#媒体])。单击(函数(){


快乐的编码!

我使用的是每个人都使用的平滑滚动javascript,有着相同的问题,就像所有顺从的小开发人员一样,我使用的是
#myCarousel

<a class="right carousel-control" href="#myCarousel" data-slide="next">


当我将
[href=media]
更改为
[href=myCarousel]
时,我的引导旋转木马控件又开始工作了。

我使用的是每个人都使用的平滑滚动javascript,并且有着相同的问题,就像所有顺从的小开发人员一样,我使用的是
\myCarousel

<a class="right carousel-control" href="#myCarousel" data-slide="next">


当我将
[href=media]
更改为
[href=myCarousel]
时,我的引导转盘控件又开始工作了。

首先,上面的答案是正确的。我只想对需要帮助的人说得更清楚一点

需要更新的代码是
SmoothScroll
函数本身。您需要从引导页面了解旋转木马的ID。只需将旋转木马ID添加到
not()。单击
函数,它将像一个符咒一样工作。下面是我所做的一个示例。更改发生在代码的第三行,您可以看到旋转木马
ID 


$(函数(){
$('a[href*=#]:不是([href=#carousel-299058])。单击(函数(){
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(目标长度){
$('html,body')。设置动画({
scrollTop:target.offset().top-70
}, 500);
返回false;
}
}
});
});

首先,上面的答案是正确的。我只想对需要帮助的人说清楚一点

需要更新的代码是
SmoothScroll
函数本身。您需要从引导页面了解旋转木马的ID。只需将旋转木马ID添加到
not()。单击
函数,它将像一个符咒一样工作。下面是我所做的一个示例。更改发生在代码的第三行,您可以看到旋转木马
ID 


$(函数(){
$('a[href*=#]:不是([href=#carousel-299058])。单击(函数(){
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(目标长度){
$('html,body')。设置动画({
scrollTop:target.offset().top-70
}, 500);
返回false;
}
}
});
});

我最近遇到了这个问题,我的解决方案是在每个链接上使用一个类,而不是在jQuery函数中使用href属性选择器

这确实意味着额外增加了一点HTML标记,但我觉得它更健壮,对项目中可能添加的其他脚本的干扰更少

因此:

$('a[href*=#]:not([href=#])').click(function() {
$('.your-class-name').click(function() {
<a href="#section" class="your-class-name">Link</a>
<div id="section">... Content ...</div>
变成这样:

$('a[href*=#]:not([href=#])').click(function() {
$('.your-class-name').click(function() {
<a href="#section" class="your-class-name">Link</a>
<div id="section">... Content ...</div>
并且您添加到页面的任何平滑滚动链接都将变成:

$('a[href*=#]:not([href=#])').click(function() {
$('.your-class-name').click(function() {
<a href="#section" class="your-class-name">Link</a>
<div id="section">... Content ...</div>

并滚动至:

$('a[href*=#]:not([href=#])').click(function() {
$('.your-class-name').click(function() {
<a href="#section" class="your-class-name">Link</a>
<div id="section">... Content ...</div>
…内容。。。

我最近遇到了这个问题,我的解决方案是在每个链接上使用一个类,而不是在jQuery函数中使用href属性选择器

这确实意味着额外增加了一点HTML标记,但我觉得它更健壮,对项目中可能添加的其他脚本的干扰更少

因此:

$('a[href*=#]:not([href=#])').click(function() {
$('.your-class-name').click(function() {
<a href="#section" class="your-class-name">Link</a>
<div id="section">... Content ...</div>
变成这样:

$('a[href*=#]:not([href=#])').click(function() {
$('.your-class-name').click(function() {
<a href="#section" class="your-class-name">Link</a>
<div id="section">... Content ...</div>
并且您添加到页面的任何平滑滚动链接都将变成:

$('a[href*=#]:not([href=#])').click(function() {
$('.your-class-name').click(function() {
<a href="#section" class="your-class-name">Link</a>
<div id="section">... Content ...</div>

并滚动至:

$('a[href*=#]:not([href=#])').click(function() {
$('.your-class-name').click(function() {
<a href="#section" class="your-class-name">Link</a>
<div id="section">... Content ...</div>
…内容。。。

别忘了添加:\\。自从JQUERY的最新版本以来,有必要添加它

$('a[href*=\\#]:not([href=\\#carousel-299058])').click(function() {

别忘了添加:\\。因为JQUERY的最新版本,所以有必要添加它

$('a[href*=\\#]:not([href=\\#carousel-299058])').click(function() {

媒体是转盘id媒体是转盘id