• js移动端 可移动滑块


    document.addEventListener('DOMContentLoaded', function() {
        //动态创建回到首页dom
        var backDom = document.createElement("div");
        backDom.className = "z-back";
        backDom.innerHTML = '<a href="/"><svg class="icon-back" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path fill="#ffffff" d="M879.461 517.238l-366.588-336.911-368.334 335.167c-6.983 6.983-6.983 17.457 0 24.441s17.457 6.983 24.441 0l343.894-314.219 343.894 314.219c3.492 3.492 6.983 5.238 12.219 5.238s8.726-1.745 12.219-5.238c5.238-5.238 5.238-15.712-1.745-22.695zM767.739 524.219c-10.474 0-17.457 6.983-17.457 17.457v267.084h-143.143v-186.784h-190.277v186.784h-143.143v-267.084c0-10.474-8.726-17.457-17.457-17.457-10.474 0-17.457 6.983-17.457 17.457v301.997h214.715v-186.784h118.704v186.784h214.715v-301.997c-1.745-10.474-8.726-17.457-19.202-17.457zM642.051 274.591h106.484v92.519c0 10.474 8.726 17.457 17.457 17.457 10.474 0 17.457-6.983 17.457-17.457v-127.433h-143.143c-10.474 0-17.457 6.983-17.457 17.457 1.745 8.726 10.474 17.457 19.202 17.457z"  /></svg></a>';
        document.body.appendChild(backDom);
        //回到首页拖拽效果
        //获取屏幕宽高
        var screenW = window.screen.availWidth;
        var screenH = window.screen.availHeight;
        var dragBox = document.querySelector(".z-back");
        dragBox.addEventListener("touchstart", function(e) {
            var touch = e.touches[0];
            startX = touch.pageX;
            startY = touch.pageY;
            var left = getCss(dragBox, "left");
            var top = getCss(dragBox, "top");
            var width = getCss(dragBox, "width");
            var height = getCss(dragBox, "height");
            dragBox.addEventListener("touchmove", function(e) {
                e.preventDefault();
                var touch = e.touches[0];
                var x = touch.pageX - startX;
                var y = touch.pageY - startY;
                var nowLeft = left + x;
                var nowTop = top + y;
                //边界值处理
                if(x > 0){
                    nowLeft = nowLeft > screenW - width ? screenW - width : nowLeft;
                }else{
                    nowLeft = nowLeft > 0 ? nowLeft : 0;
                }
                if(y > 0){
                    nowTop = nowTop > screenH - height ? screenH - height : nowTop;
                }else{
                    nowTop = nowTop > 0 ? nowTop : 0;
                }
                dragBox.style.left = nowLeft + "px";
                dragBox.style.top = nowTop + "px";
            }, false);
        }, false);
        dragBox.addEventListener("touchend", function(e) {
            dragBox.removeEventListener("touchstart,touchmove,touchend", function() {
    
            });
        }, false)
    }, false);
    
    //获取元素样式
    function getCss(curEle, attr) {
        var val = null,
            reg = null;
        if ("getComputedStyle" in window) {
            val = window.getComputedStyle(curEle, null)[attr];
        } else {
            if (attr === "opacity") {
                val = curEle.currentStyle["filter"];
                reg = /^alpha(opacity=(d+(?:.d+)?))$/i;
                val = reg.test(val) ? reg.exec(val)[1] / 100 : 1;
            } else {
                val = curEle.currentStyle[attr];
            }
        }
        reg = /^(-?d+(.d+)?)(px|pt|rem|em)?$/i;
        return reg.test(val) ? parseFloat(val) : val;
    }
  • 相关阅读:
    CSS3 Animation
    css形状大全
    HTML5 表单属性
    HTML5 Input 类型
    HTML 5 服务器发送事件
    jq制作博客已存在多少天
    Java网络编程与NIO详解4:浅析NIO包中的Buffer、Channel 和 Selector
    Java网络编程和NIO详解3:IO模型与Java网络编程模型
    Java网络编程与NIO详解2:JAVA NIO 一步步构建IO多路复用的请求模型
    Java网络编程和NIO详解1:JAVA 中原生的 socket 通信机制
  • 原文地址:https://www.cnblogs.com/zhuzeliang/p/8385805.html
Copyright © 2020-2023  润新知