これら 2 つをマージして機能を強化し、編集を容易にする方法を教えてください。
上の 1 つは Screen Re-size で関数を起動するためのもので、もう 1 つはロード時に画面サイズを検出するためのものです。
関数全体:
(function(){
//detect the width on page load//
$(document).ready(function(){
var width = $(window).width();
if(width <= 770){
$('#home-sectionB img').insertBefore($('#home-sectionB span'));
$('.detailsBox').insertBefore($('.imagesGrid'));
} else {
$('#home-sectionB span').insertBefore($('#home-sectionB img'));
$('.imagesGrid').insertBefore($('.detailsBox'));
}
});
//update the width value when the browser is resized//
$(window).resize(function(){
var width = $(window).width();
if(width <= 770){
$('#home-sectionB img').insertBefore($('#home-sectionB span'));
$('.detailsBox').insertBefore($('.imagesGrid'));
} else {
$('#home-sectionB span').insertBefore($('#home-sectionB img'));
$('.imagesGrid').insertBefore($('.detailsBox'));
}
});
})(jQuery);
トップセクション:
(function(){
//detect the width on page load//
$(document).ready(function(){
var width = $(window).width();
if(width <= 770){
$('#home-sectionB img').insertBefore($('#home-sectionB span'));
$('.detailsBox').insertBefore($('.imagesGrid'));
} else {
$('#home-sectionB span').insertBefore($('#home-sectionB img'));
$('.imagesGrid').insertBefore($('.detailsBox'));
}
});
底部:
//update the width value when the browser is resized//
$(window).resize(function(){
var width = $(window).width();
if(width <= 770){
$('#home-sectionB img').insertBefore($('#home-sectionB span'));
$('.detailsBox').insertBefore($('.imagesGrid'));
} else {
$('#home-sectionB span').insertBefore($('#home-sectionB img'));
$('.imagesGrid').insertBefore($('.detailsBox'));
}
});
})(jQuery);