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?
ringa_lee2017-05-18 11:04:18
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("隐藏") //处理
}
}
高洛峰2017-05-18 11:04:18
$(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("隐藏") //处理
}
}