为了账号安全,请及时绑定邮箱和手机立即绑定

bootstrap轮播图?

bootstrap轮播图?

最近在做一个响应式的个人博客网站。 用的bootstrap做的轮播图,体验很好; 那么问题来了: 移动端怎么通过触摸屏幕切换轮播图片? 抛弃别的框架如:swiper等(swiper我用了,可以)先不说, 能不能不引入别的框架解决此问题, 或者之前有同志遇到类似问题的, 求告一下解决方案, 本人有严重强迫症, 不完美的不行。 谢谢各位老铁先。
查看完整描述

1 回答

?
幕布斯7574896

TA贡献38条经验 获得超3个赞

用js监听滑动事件,然后调用轮播接口即可。这里有份示例:

<script type = "text/javascript" >
var isTouch = ('ontouchstart' in window);
if (isTouch) {
    $(".carousel").on('touchstart',
    function(e) {
        var that = $(this);
        var touch = e.originalEvent.changedTouches[0];
        var startX = touch.pageX;
        var startY = touch.pageY;
        $(document).on('touchmove',
        function(e) {
            touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
            var endX = touch.pageX - startX;
            var endY = touch.pageY - startY;
            if (Math.abs(endY) < Math.abs(endX)) {
                if (endX > 10) {
                    $(this).off('touchmove');
                    that.carousel('prev');
                } else if (endX < -10) {
                    $(this).off('touchmove');
                    that.carousel('next');
                }
                return false;
            }
        });
    });
    $(document).on('touchend',
    function() {
        $(this).off('touchmove');
    });
} < /script>


查看完整回答
反对 回复 2018-05-11
  • 1 回答
  • 0 关注
  • 2272 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信