栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

jQuery实现360°全景拖动展示

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

jQuery实现360°全景拖动展示

CSS

复制代码 代码如下:
html,body{background:#333;}
 #loading{left:0;top:0;width:100%;height:100%;background:#333;color:#fff;}
 #loading span{left:45%;top:40%;font:normal 50px Arial;color:#fff;}
 #demo{left:50%;top:50%;margin-left:-512px;margin-top:-384px;width:1024px;height:768px;}
 #demo img{border-radius:8px;border:5px solid #555;}
 .back{font-size:18px;line-height:130%;padding:8px 20px;color:#fff;}
 #back-home{left:0px;top:0px;background:#35916D;}
 #back-article{right:0px;top:0px;background:#444;}
 #back-download{right:0px;bottom:0px;background:#CE565D;}

HTML

复制代码 代码如下:


js

复制代码 代码如下:



drag.js

复制代码 代码如下:
(function($){
    $.fn.drag360=function(images){
        var mdx,mmx,isDrag=false,unitStep=40,current=0;
        var that=$(this);
        var length=images.length;
        //触摸 
        that.on('touchstart',function(e){
            var touch = e.originalEvent;
                mdx = touch.changedTouches[0].pageX;
                isDrag=true;
        }).on('touchmove',function(e){
            e.preventDefault();
            touch = e.originalEvent.touches[0]||e.originalEvent.changedTouches[0];
            mmx=touch.pageX;
            if(isDrag){
                if(Math.abs(mmx-mdx)>unitStep){
                    if(mmx-mdx>0){
                        current=current+1;
                    }else{
                        current=current-1;
                    }
                    mdx=mmx;
                    if(current<0)current=length-1;
                    if(current>length-1)current=0;
                    that.attr("src",images[current]);
                }
            }
        }).on('touchend',function(e){
            isDrag=false;
        });
        //拖动
        that.on('mousedown',function(e){
            mdx=e.pageX;
            isDrag=true;
        }).on('mousemove',function(e){
            mmx=e.pageX;
            if(isDrag){
                if(Math.abs(mmx-mdx)>unitStep){
                    current=current+(mmx-mdx>0?1:-1);
                    mdx=mmx;
                    if(current<0)current=length-1;
                    if(current>length-1)current=0;
                    that.attr("src",images[current]);
                }
            }
            return false;
        })
        $(document).on('mouseup',function(e){
            isDrag=false;
        });
        $(document).on('mouseleave',function(e){
            isDrag=false;
        });
        return this;
    };
})(jQuery);

以上所述就是本文的全部内容了,希望大家能够喜欢。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/103425.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号