首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Hammer.js不起作用

Hammer.js不起作用
EN

Stack Overflow用户
提问于 2014-08-07 12:59:28
回答 1查看 1.5K关注 0票数 0

第一次我使用hammer.js使旋转木马触摸左右滑动。这个旋转木马是通过引导-carousel.js构建的。但触控刷卡不起作用。我对js很陌生,所以无法找到解决方案。你能检查一下这里出了什么问题吗?

我试过:

代码语言:javascript
复制
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
 <script src="http://hammerjs.github.io/dist/hammer.min.js"></script>

<script>
$(document).ready(function() {  
        $('.carousel-inner').hammer().on('swipeleft', function(){
            $(this).carousel('prevslide()'); 

        })
        $('.carousel-inner').hammer().on('swiperight', function(){
            $(this).carousel('nextslide()'); 

        })
 });

代码语言:javascript
复制
$(window).load(function(){ 
        $('.carousel-inner').hammer().on('swipeleft', function(){
                  $(".carousel-control.left").click() 
        })
        $('.carousel-inner').hammer().on('swiperight', function(){
             $(".carousel-control.right").click()
        })


    });

HTML:

代码语言:javascript
复制
<div class="carousel slide row-fluid" id="testimonials-carousal">
            <!-- Carousel items -->
            <div class="carousel-inner">
               <div ng-repeat="testimonial in testimonials | limitTo : 5" class="item ng-scope" ng-class="{'active' : $index==0}"> 
                    <div ng-class="{'span10':!testimonial.clientImage, 'span8':testimonial.clientImage}" class="offset1 span10">
                        <div class="testiContent">
                            <i class="pt pt-icon-quote-left testiQuoteTop"></i>
                            <i class="pt pt-icon-quote-right testiQuoteBottom"></i>
                            <span ng-bind-html="testimonial.clientComment" class="testiDesContent ng-binding">I purchased a flat through xyz in Pune. I  am highly satisfied with the services provided by abc.</span>                        </div>

                        <div class="testClientInfo ng-binding">Abhishek Prasad
                            <span class="testClientCompInfo ng-binding"></span>
                        </div>
                    </div>
                    <!-- ngIf: testimonial.clientImage -->
                </div><!-- end ngRepeat: testimonial in testimonials | limitTo : 5 --><div ng-repeat="testimonial in testimonials | limitTo : 5" class="item ng-scope" ng-class="{'active' : $index==0}"> 
                    <div ng-class="{'span10':!testimonial.clientImage, 'span8':testimonial.clientImage}" class="offset1 span10">
                        <div class="testiContent">
                            <i class="pt pt-icon-quote-left testiQuoteTop"></i>
                            <i class="pt pt-icon-quote-right testiQuoteBottom"></i>
                            <span ng-bind-html="testimonial.clientComment" class="testiDesContent ng-binding">I purchased a flat through xyz in Pune. I  am highly satisfied with the services provided by abc.</span>                        </div>

                        <div class="testClientInfo ng-binding">Mr. Rajeev Ranjan
                            <span class="testClientCompInfo ng-binding"></span>
                        </div>
                    </div>
                    <!-- ngIf: testimonial.clientImage -->
                </div><!-- end ngRepeat: testimonial in testimonials | limitTo : 5 -->
            </div>
            <!-- Carousel nav -->
            <a ng-click="prevslide()" class="carousel-control left"><i class="pt pt-icon-angle-left"></i></a>
            <a ng-click="nextslide()" class="carousel-control right"><i class="pt pt-icon-angle-right"></i></a>
        </div>

我花了很多时间研究这件事。你们能帮帮我吗

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-07 13:40:43

  • 根据文档,正确的参数是prevnext
  • 在处理程序中,this将引用.carousel-inner而不是被初始化为carousel的实际父元素,因此尝试以下操作 $(.ready).ready(函数(){$(‘..carousel inner’).hammer().on(‘swipeleft’,function(){ $(this).parent().carousel('prev');}) .on函数(){$(This).parent().carousel(‘next’;}) };
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25183200

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档