I am wanting to append some HTML content from a variable for smaller screen sizes.However when I resize the browser the content appends(as it should) but if I keep moving the window it continues to append multiple copies of the HTML.
How could I prevent it from doing this?
This what I am doing:
function adjustStyle(width) {
width = parseInt(width);
if (width < 700) {
$('ul.nav li.top ul.submenu').removeAttr("style");
$('body').append(str); // this is when I am having the problem appending
} else if (width >= 700) {
$('ul.nav').removeAttr("style");
$('.form-wrapper').removeAttr("style");
var toggle = function(direction, display) {
return function() {
var self = this;
var ul = $('ul.submenu', this);
if( ul.css('display') === display && !self['block' + direction] ) {
self['block' + direction] = true;
ul['slide' + direction]('fast', function() {
self['block' + direction] = false;
});
}
};
};
$('ul.nav li.top').hover(toggle('Down', 'none'), toggle('Up', 'block'));
$('ul.nav li.top ul.submenu').hide();
$('#gallery').remove();
} else {
}
}
$(function() {
adjustStyle($(this).width());
$(window).resize(function() {
adjustStyle($(this).width());
});
});
You need to debounce the resize event such that it fires only when resize is complete.
This is required because –
Following is a snippet from my answer to this question.
In addition to this, I suggest you have a placeholder for adding your content –