윈도우의 너비에 따라 파일에서 일부 HTML을로드하는 스크립트를 작성했습니다.jQuery 창 너비가 일부 중단 점에서 작동하지 않습니다.
문제는 몇 가지 점에서 그것은 그래서 문제가 주위에 온다
- 1281px 1295px에 폭
var winWidth = $(window).width(); //var winWidth = window.outerWidth; //var winWidth = document.body.offsetWidth; if((winWidth > 0) && (winWidth <= 767)){ console.log('Mobile'); $.ajax({ url : "home-banner-parts/mobile.html", dataType: "html", success : function (data) { $("#homeslider").html(data); } }); } if((winWidth >= 768) && (winWidth <= 1279)){ console.log('Tab'); $.ajax({ url : "home-banner-parts/tab.html", dataType: "html", success : function (data) { $("#homeslider").html(data); } }); } if((winWidth >= 1280)){ console.log('Desktop'); $.ajax({ url : "home-banner-parts/desktop.html", dataType: "html", success : function (data) { $("#homeslider").html(data); } }); } //the above code is wrapped in function $(window).resize(function() { console.log('Resizing'); homeCarousel(); });
작동하지 것입니다 -로드 tab.html하지만 sektop.html
를로드한다
- 770x785 픽셀 - mobile.html을로드하지만 tab.html을로드해야합니다.
lp
당신이 (winWidth를) CONSOLE.LOG를 추가 할 수 있습니다, 당신에게 코드를 호출한다 현재 너비를 추적하기 위해 IF 문보다 위에? – cosmoonot
내가 그랬고, 크기 조정시 크롬으로 표시되는 올바른 것을 보여주지 못합니다 - 불일치가 있습니다. –
오, 크기를 조정 중입니다. $ (window) .on ('load resize', function() {// 여기에 코드.}); – cosmoonot