教你一招实现3D图片演示


当前第2页 返回上一页

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

// 滚轮滚动

// 监听鼠标滚轮事件,该函数不用调用直接生效

document.onmousewheel = function(e){

    // console.log(e)

    e = e || window.event

    var d  = e.wheelDelta / 10 || -e.detail

    radius += d

    init(1)

 

}

var sX,sY,nX,nY,desX = 0 , desY = 0, tX = 0,tY = 0;

// 鼠标拖动页面

document.onpointerdown = function(e){

    // console.log(e);

    e = e || window.event//防止出错,如果e不存在,则让window.event为e

    var sX = e.clientX,

    sY = e.clientY

    //监听鼠标移动函数

    this.onpointermove = function(e){

        console.log(e);

        e = e || window.event//防止出错,如果e不存在,则让window.event为e

        var nX = e.clientX,

            nY = e.clientY;

        desX = nX - sX;//在x轴上滑动的距离

        desY = nY - sY;

        tX += desX * 0.1

        tY += desY * 0.1

        // 让页面跟着鼠标动起来

        applyTransform(oDarg)

    }

    this.onpointerup = function(e){

        //每个多久实现一次setInterval

        oDarg.timer = setInterval(function(){

            desX *= 0.95

            desY *= 0.95

            tX += desX * 0.1

            tY += desY * 0.1

            applyTransform(oDarg)

            playSpin(false)

            if(Math.abs(desX) < 0.5 && Math.abs(desY) < 0.5){

                clearInterval(oDarg.timer)

                playSpin(true)

            }

        },17)

        this.onpointermove = this.onpointerup = null

    }

    return false

}

function applyTransform(obj){

    if(tY > 180)tY = 180

    if(tY < 0)tY = 0

    obj.style.transform = `rotateX(${-tY}deg) rotateY(${tX}deg)`

}

 

function playSpin(yes){

    oSpin.style.animationPlayState = (yes ? 'running' : 'paused')

}

【推荐学习:javascript高级教程

以上就是教你一招实现3D图片演示的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

教你一招实现3d图片演示

纯css3实现3d翻转效果的代码示例

更多相关阅读请进入《3d》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...