我们如何将这两者合并在一起以增强功能并使其更易于编辑。
最上面的一项是在 Screen Re-size 上触发功能,另一项是在加载时检测屏幕尺寸。
整体功能:
(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);