面馆师傅 2022-07-25 16:00 采纳率: 73.7%
浏览 141
已结题

html下拉刷新,怎么解决点击也会刷新?

哪里错了吗,手机点网页也会自动 下拉刷新?有办法解决吗?

<style type="text/css">
#slideDown{margin-top: 0;width: 100%;}
#slideDown1,#slideDown2{width: 100%;height: 70px;;background: #e9f4f7;display: none;}
#slideDown1{height: 20px;}
#slideDown1>p,#slideDown2>p{margin: 20px auto;text-align:center;font-size: 14px;color: #37bbf5;}
</style>
    </head>
    <body id="content">
        <div>
<div id="slideDown">
<div id="slideDown1">
<p>松开刷新</p>
</div>
<div id="slideDown2">
<p>正在刷新 ...</p>
</div>
</div>
<div>
<ul>
<li>item1 -- item1555555555 -- item1aaaaaaa</li>
<li>item2 -- item2 -dsfasd- item2</li>
<li>item3 -- item3 -- item3</li>
<li>item4 -- item4 -- item4</li>
<li>item5 -- item5 -- item5</li>
<li>item6 -- item6 -- item6</li>
<li>item7 -- item7 -- item7</li>
</ul>
</div>
</div>
    </body>
</html>
<script type="text/javascript">
function slideDownStep1(dist){
var slideDown1 = document.getElementById("slideDown1"),
slideDown2 = document.getElementById("slideDown2");
slideDown2.style.display = "none";
slideDown1.style.display = "block";
slideDown1.style.height = (parseInt("20px") - dist) + "px";
}
function slideDownStep2(){
var slideDown1 = document.getElementById("slideDown1"),
slideDown2 = document.getElementById("slideDown2");
slideDown1.style.display = "none";
slideDown1.style.height = "20px";
slideDown2.style.display = "block";
}
function slideDownStep3(){
var slideDown1 = document.getElementById("slideDown1"),
slideDown2 = document.getElementById("slideDown2");
slideDown1.style.display = "none";
slideDown2.style.display = "none";
}
k_touch("content","y");
function k_touch(contentId,way){
var _start = 0,
_end = 0,
_content = document.getElementById(contentId);
_content.addEventListener("touchstart",touchStart,false);
_content.addEventListener("touchmove",touchMove,false);
_content.addEventListener("touchend",touchEnd,false);
function touchStart(event){
var touch = event.targetTouches[0];
if(way == "x"){
_start = touch.pageX;
}else{
_start = touch.pageY;
}
}
function touchMove(event){
var touch = event.targetTouches[0];
if(way == "x"){
_end = (_start - touch.pageX);
}else{
_end = (_start - touch.pageY);
if(_end < 0){
slideDownStep1(_end);
}
}
}
function touchEnd(event){
if(_end >0){
console.log("左滑或上滑 "+_end);
}else{
console.log("右滑或下滑"+_end);
slideDownStep2();
setTimeout(function(){
slideDownStep3();
},2500);
}
}
}
</script>
  • 写回答

5条回答

  • eq0284 2022-07-25 17:05
    关注

    我修改了你的touchstart touchend,你看看

    
    <html>
    
    <head>
        <script type="text/javascript">
            window.onload = function () {
    
    
                function slideDownStep1(dist) {
                    var slideDown1 = document.getElementById("slideDown1"),
                        slideDown2 = document.getElementById("slideDown2");
                    slideDown2.style.display = "none";
                    slideDown1.style.display = "block";
                    slideDown1.style.height = (parseInt("20px") - dist) + "px";
                }
                function slideDownStep2() {
                    var slideDown1 = document.getElementById("slideDown1"),
                        slideDown2 = document.getElementById("slideDown2");
                    slideDown1.style.display = "none";
                    slideDown1.style.height = "20px";
                    slideDown2.style.display = "block";
                }
                function slideDownStep3() {
                    var slideDown1 = document.getElementById("slideDown1"),
                        slideDown2 = document.getElementById("slideDown2");
                    slideDown1.style.display = "none";
                    slideDown2.style.display = "none";
                }
                k_touch("content", "y");
                function k_touch(contentId, way) {
                    var _start = 0,
                        _end = 0,
                        _content = document.getElementById(contentId);
                    _content.addEventListener("touchstart", touchStart, false);
                    _content.addEventListener("touchmove", touchMove, false);
                    _content.addEventListener("touchend", touchEnd, false);
                    function touchStart(event) {
                        _start = 0
                        _end = 0
                        var touch = event.targetTouches[0];
                        if (way == "x") {
                            _start = touch.pageX;
                        } else {
                            _start = touch.pageY;
                        }
                    }
                    function touchMove(event) {
                        var touch = event.targetTouches[0];
                        if (way == "x") {
                            _end = (_start - touch.pageX);
                        } else {
                            _end = (_start - touch.pageY);
                            if (_end < 0) {
                                slideDownStep1(_end);
                            }
                        }
                    }
                    function touchEnd(event) {
                        if (_end == 0) {
                            console.log("点击屏幕")
                            return
                        }
                        if (_end > 0) {
                            console.log("左滑或上滑 " + _end);
                        } else {
                            console.log("右滑或下滑" + _end);
                            slideDownStep2();
                            setTimeout(function () {
                                slideDownStep3();
                            }, 2500);
                        }
                    }
                }
            }
        </script>
    
        <style type="text/css">
            #slideDown {
                margin-top: 0;
                width: 100%;
            }
    
            #slideDown1,
            #slideDown2 {
                width: 100%;
                height: 70px;
                ;
                background: #e9f4f7;
                display: none;
            }
    
            #slideDown1 {
                height: 20px;
            }
    
            #slideDown1>p,
            #slideDown2>p {
                margin: 20px auto;
                text-align: center;
                font-size: 14px;
                color: #37bbf5;
            }
        </style>
    </head>
    
    <body id="content">
        <div>
            <div id="slideDown">
                <div id="slideDown1">
                    <p>松开刷新</p>
                </div>
                <div id="slideDown2">
                    <p>正在刷新 ...</p>
                </div>
            </div>
            <div>
                <ul>
                    <li>item1 -- item1555555555 -- item1aaaaaaa</li>
                    <li>item2 -- item2 -dsfasd- item2</li>
                    <li>item3 -- item3 -- item3</li>
                    <li>item4 -- item4 -- item4</li>
                    <li>item5 -- item5 -- item5</li>
                    <li>item6 -- item6 -- item6</li>
                    <li>item7 -- item7 -- item7</li>
                </ul>
            </div>
        </div>
    </body>
    
    </html>
    

    您的采纳就是对我最大的动力,谢谢!!!

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(4条)

报告相同问题?

问题事件

  • 系统已结题 8月4日
  • 已采纳回答 7月27日
  • 修改了问题 7月25日
  • 创建了问题 7月25日

悬赏问题

  • ¥50 comsol稳态求解器 找不到解,奇异矩阵有1个空方程返回的解不收敛。没有返回所有参数步长;pid控制
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功