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);
});
});
//執(zhí)行函數(shù)
function show_taboo(){
if(distance>200){
alert("出現(xiàn)了")//做處理
}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?
學(xué)習(xí)是最好的投資!
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();//獲得監(jiān)聽事件的值
if(distance>200){
alert("出現(xiàn)了")//做處理
}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)
});
});
//執(zhí)行函數(shù)
function show_taboo(distance){
if(distance>200){
alert("出現(xiàn)了")//做處理
}else{
alert("隱藏") //處理
}
}