Answer the question
In order to leave comments, you need to log in
How to disable js execution under certain conditions?
I have js code
<script type="text/javascript">
$(document).ready(function() {
var v = $("#sticknavbar");
var z = $("#sticknavbottomid")
var stickyHeaderTop = v.offset().top;
$(window).scroll(function() {
if ( $(window).scrollTop() >= stickyHeaderTop) {
v.addClass("sticknav"); //добавить класс sticknav
z.addClass("sticknavbottom");
} else {
v.removeClass(); //при достижении нижней части убрать sticknav
z.removeClass("sticknavbottom");
}
});
});
</script>
Answer the question
In order to leave comments, you need to log in
1) Set the window resize event to save the size of this window. Check (when resizing) whether the width is larger than necessary.
2)
if ( $( "#myDiv" ).length ) {
// элемент есть
$( "#myDiv" ).show();
}
I'll answer myself. I solved the issue like this:
<script type="text/javascript">
var isMobile = {
Android: function() { return navigator.userAgent.match(/Android/i) ? true : false; },
BlackBerry: function() { return navigator.userAgent.match(/BlackBerry/i) ? true : false; },
iOS: function() { return navigator.userAgent.match(/iPhone|iPad|iPod/i) ? true : false; },
Windows: function() { return navigator.userAgent.match(/IEMobile/i) ? true : false; },
any: function() { return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows()); }
};
if ( !isMobile.any() ) {
$(document).ready(function() {
var v = $("#sticknavbar");
var z = $("#sticknavbottomid")
var stickyHeaderTop = v.offset().top;
$(window).scroll(function() {
//var windowpostest = $(window).scrollTop();
//v.html("расстояния от верха" + "<br />"+ stickyHeaderTop + "<br /> mestopozhenie " + windowpostest + "<br />"+ v.offset().top
//);
if ( $(window).scrollTop() >= stickyHeaderTop) {
v.addClass("sticknav"); //добавить класс sticknav
z.addClass("sticknavbottom");
} else {
v.removeClass(); //при достижении нижней части убрать sticknav
z.removeClass("sticknavbottom");
}
});
});
}
</script>
var isMobile = {
Android: function() { return navigator.userAgent.match(/Android/i) ? true : false; },
BlackBerry: function() { return navigator.userAgent.match(/BlackBerry/i) ? true : false; },
iOS: function() { return navigator.userAgent.match(/iPhone|iPad|iPod/i) ? true : false; },
Windows: function() { return navigator.userAgent.match(/IEMobile/i) ? true : false; },
any: function() { return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows()); }
};
if ( !isMobile.any() ) {
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question