javascript - How to slide the screen on the mobile phone to get the distance from the top of a certain element? At the same time, can this value be referenced by other functions?
PHPz
PHPz 2017-05-18 11:02:18
0
2
610

As the title says, what I want to achieve is to slide the mobile phone screen. When an element is a certain value from the top (for example, 200px), click the pop-up button on the screen, and the position of the pop-up layer will be 200px from the top

$(document).ready(function(){
    $('.content_box').bind('touchstart', function(e) {
        var a =$(".article_box").offset().top;
        distance = a;
        console.log(distance);
    });
});
//执行函数
function show_taboo(){
    if(distance>200){
        alert("出现了")//做处理
    }else{
        alert("隐藏")、、处理
}

What I want to achieve is this effect. The value of distance can be obtained, but it cannot be referenced in the show function. Can you please help me?

PHPz
PHPz

学习是最好的投资!

reply all(2)
左手右手慢动作

The solution found is as follows:
$(document).ready(function(){

         $('.content_box').bind('touchstart', test());
 });

//Define function
function test(){

 return $(".content_box").offset().top;      

}
//Execute function
function show_taboo(){

distance = test();//获得监听事件的值
if(distance>200){
    alert("出现了")//做处理
}else{
    alert("隐藏") //处理
}

}

小葫芦
$(document).ready(function(){
                    $('.content_box').bind('touchstart', function(e) {
                    var a = $(".content_box").offset().top;
                    distance = a;
                    console.log(distance)
                    return show_taboo(distance)
                    });
            });
            //执行函数
            function show_taboo(distance){
                if(distance>200){
                    alert("出现了")//做处理
                }else{
                    alert("隐藏") //处理
                }
            }
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template