我需要能够在窗口调整大小时禁用/重新启用Javascript吗? 目前,当桌面上的窗口调整大小时,导航栏会粘住并且是唯一可见的而不是内容。
<script>
if ( $(window).width() <= 1200 ) {
}else{
$('nav').addClass('original').clone().insertAfter('nav').addClass('cloned').css('position','fixed').css('top','0').css('margin- top','0').css('z-index','500').removeClass('original').hide();
scrollIntervalID = setInterval(stickIt, 10);
function stickIt() {
var orgElementPos = $('.original').offset();
orgElementTop = orgElementPos.top;
if ($(window).scrollTop() >= (orgElementTop)) {
as original element.
orgElement = $('.original');
coordsOrgElement = orgElement.offset();
leftOrgElement = coordsOrgElement.left;
widthOrgElement = orgElement.css('width');
th',widthOrgElement).show();
$('.original').css('visibility','hidden');
} else {
$('.cloned').hide();
$('.original').css('visibility','visible');
}
}
</script>
答案 0 :(得分:1)
您可以将事件处理程序绑定到“resize”JavaScript事件:
var lines = File.ReadLines(filepath).Skip(2);
只要浏览器窗口的大小发生变化,您的代码就会被执行。
答案 1 :(得分:1)
$(window).resize(function() {
if($(window).width() <= 1200) {
//small screen code
}else {
//large screen code }
});
//trigger window resize event on load
$(window).trigger('resize');
答案 2 :(得分:1)
你可以通过检查窗口宽度
来做到这一点var winWidth = $(window).width(); // you can get the window width from this
//Then check with the condtion(compare with your need ex :)
if(winWidth <= 600)
{
//your work here
alert("window resize less than or equal to 600");
}
else
{
//your work here
alert("window resize greater than to 600");
}