基于vue的图片查看工具

图片说明
可以切换图片
图片说明
功能:
1.上一页;
2.下一页;
3.放大(根据个人喜好调整幅度);
4.缩小(根据个人喜好调整幅度);
5.旋转(顺时针,逆时针同理所以不写了);
6.重置;

//**上代码;***//

<style>
    .screen {
        width: 50vw;
        height: 50vh;
        position: relative;
        overflow: hidden;
        background:linear-gradient(90deg,rgb(2, 43, 66),rgb(14, 21, 61));
    }

    .screen-item {
        width: 35vw;
        height: 35vh;
        top: 7.5vh;
        left: 7.5vw;
        position: absolute;
    }
    .tabbar {
        width: 240px;
        height: 35px;
        position: absolute;
        bottom: 1px;
        background-color: white;
        display: flex;
        justify-content: space-between;
        left: calc(25vw - 120px);
    }

</style>
<script>


    new Vue({
        el: "#viewer",
        data: {
            msg: "测试",
            value: 0,
            currentUrl:"",
            imgList:["./images/atz.jpg","./images/sbl.jpg"]
        },
        mounted() {
            // 初始化;
            this.currentUrl = this.imgList[0];
        },
        methods: {
            dragEvent(e) {
                // e.target.offsetLeft js获取到元素的left;
                // e.target.offsetTop js获取到元素的top;
                // 监听全局鼠标移动事件;
                let eOffsetLeft = e.target.offsetLeft;
                let eOffsetTop = e.target.offsetTop;
                document.onmousemove = (ev)=> {

                    let disX = eOffsetLeft + (ev.clientX - e.clientX);
                    let disY = eOffsetTop + (ev.clientY - e.clientY);
                    this.$refs.screenItem.style.left = `${disX}px`;
                    this.$refs.screenItem.style.top = `${disY}px`;
                    return false;
                }
                document.onmouseup = function() {
                    document.onmousemove = null;
                    document.onmouseup = null;
                }
                return false;
            },


            // 放大事件;
            ampEvent() {
                let currentWidth = this.$refs.screenItem.offsetWidth;
                let currentHeight = this.$refs.screenItem.offsetHeight;
                currentWidth += 40;
                currentHeight += 40;
                this.$refs.screenItem.style.width = currentWidth+"px";
                this.$refs.screenItem.style.height = currentHeight+"px";
            },
            // 缩小事件;
            shrink() {
                let currentWidth = this.$refs.screenItem.offsetWidth;
                let currentHeight = this.$refs.screenItem.offsetHeight;

                currentWidth -= 40;
                currentHeight -= 40;

                this.$refs.screenItem.style.width = currentWidth+"px";
                this.$refs.screenItem.style.height = currentHeight+"px";
            },
            //旋转事件;
            rotate() {
                if(!this.$refs.screenItem.style.transform) {
                    this.$refs.screenItem.style.transform = "rotate(90deg)";
                }else {
                    let reg = /\d{1,}/;
                    let currentValue = reg.exec(this.$refs.screenItem.style.transform)[0]*1;
                    currentValue += 90;
                    this.$refs.screenItem.style.transform = `rotate(${currentValue}deg)`;

                }
            },
            // 还原事件;
            reset() {
                //默认值;
                let defaultWidth = "35vw";
                let defaultHeight = "35vh";
                let defaultLeft = "7.5vw";
                let defaultTop = "7.5vh";
                let defaultRotate = "rotate(0deg)";
                //赋值
                this.$refs.screenItem.style.width = defaultWidth;
                this.$refs.screenItem.style.height = defaultHeight;
                this.$refs.screenItem.style.left = defaultLeft;
                this.$refs.screenItem.style.top = defaultTop;
                this.$refs.screenItem.style.transform = defaultRotate;

            },
            // 上一页事件;
            prevEvent() {
                // 调用reset方法先重置图片状态;
                this.reset();
                let index = this.imgList.indexOf(this.currentUrl);
                if (index == 0) {
                    this.currentUrl = this.imgList[0];
                    alert("当前是第一张图片了");
                }
                else {
                    index--;
                    this.currentUrl = this.imgList[index];
                }

            },


            //下一页方法;
            nextEvent() {
                // 调用reset方法先重置图片状态;
                this.reset();
                let index = this.imgList.indexOf(this.currentUrl);
                if (index == this.imgList.length - 1) {
                    this.currentUrl = this.imgList[this.imgList.length - 1];
                    alert("当前是最后一张张图片了");
                }
                else {
                    index++;
                    this.currentUrl = this.imgList[index];
                }
            }
        },

    })
</script>
全部评论

相关推荐

Yushuu:你的确很厉害,但是有一个小问题:谁问你了?我的意思是,谁在意?我告诉你,根本没人问你,在我们之中0人问了你,我把所有问你的人都请来 party 了,到场人数是0个人,誰问你了?WHO ASKED?谁问汝矣?誰があなたに聞きましたか?누가 물어봤어?我爬上了珠穆朗玛峰也没找到谁问你了,我刚刚潜入了世界上最大的射电望远镜也没开到那个问你的人的盒,在找到谁问你之前我连癌症的解药都发明了出来,我开了最大距离渲染也没找到谁问你了我活在这个被辐射蹂躏了多年的破碎世界的坟墓里目睹全球核战争把人类文明毁灭也没见到谁问你了😆
点赞 评论 收藏
分享
牛客101244697号:这个衣服和发型不去投偶像练习生?
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务