[英]How to hide a div when the position of another div is less than a certain value
I'm trying to hide #back when #mobile-nav is positioned 0vw from the left.当#mobile-nav 位于左侧 0vw 时,我试图隐藏 #back。 Here's what I have at the moment...这是我目前所拥有的......
$(document).ready(function() {
var position = $("#mobile-nav").css("left", "0vw");
if (position < 0vw) {
$("#back").css("display", "none");
} else {
$("#back").css("display", "block");
}
);
Any idea as to why this isn't returning successfully?关于为什么这没有成功返回的任何想法? Here's a link to the codepen https://codepen.io/spittman/pen/pBqYON这是代码笔的链接https://codepen.io/spittman/pen/pBqYON
Try this:尝试这个:
var position = parseInt($("#mobile-nav").css("left"));
if (position <= 0) {
$("#back").css("display", "none");
}
else {
$("#back").css("display", "block");
}
try this尝试这个
$("ul ul").hide();
$("li").click(function(event) {
$(this).children('ul').toggle();
event.stopPropagation();
});
$("li").click(function() {
$(this).siblings().children().hide();
});
$(".nav-child-trigger").click(function(){
$("#mobile-nav").animate({left: '-=100vw'});
});
$("#back").click(function(){
$("#mobile-nav").animate({left: '+=100vw'});
var position = $("#mobile-nav").position().left;
if (position > 0) {
$("#back").css("display", "none");
}
else {
$("#back").css("display", "block");
}
});
$(document).ready(function(){
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.