1
캐 러셀이 있는데 브라우저의 현재 너비를 기준으로 슬라이드 슬라이드의 위치를 다시 잡아야합니다. 내가 따라야 할 규칙은 다음과 같습니다 창 크기 변경시 배경 위치 변경으로 인해 이미지가 깜박임
browserWidth > 1200: do not reposition slide
browserWidth > 960 && browserWidth < 1200: move slide background X position based
on the formula (25/48*browserWidth)-625
browserWidth < 960: reposition background X position to -125px
는 좀 자바 스크립트를 이렇게 썼다,하지만 브라우저의 크기를 조정할 때마다 이미지가 많이을 깜박이기 시작합니다. 컴퓨터가 고해상도이므로 배경 이미지를 다시 렌더링하는 데 문제가 있다고 가정합니다. 이 깜박이는 문제를 해결할 수있는 방법이 있습니까?
$(window).resize(function() {
var winW = $(window).width();
if (winW > 960 && winW < 1200) {
$('#' + carouselID).css('left', '600px');
var leftValue = ((25/48) * winW - 625) + 'px';
var backgroundAtr = 'url(http://www.placehold.it/1200x800) ' + leftValue + ' top no-repeat';
$('#' + carouselID + ' .slides .slide').css('background', backgroundAtr);
} else if (winW <= 960) {
$('#' + carouselID).css('left', '600px');
var leftValue = '-125px';
var backgroundAtr = 'url(http://www.placehold.it/1200x800) ' + leftValue + ' top no-repeat';
$('#' + carouselID + ' .slides .slide').css('background', backgroundAtr);
} else if (winW >= 1200) {
$('#' + carouselID).css('left', '50%');
var leftValue = 'left';
var backgroundAtr = 'url(http://www.placehold.it/1200x800) ' + leftValue + ' top no-repeat';
$('#' + carouselID + ' .slides .slide').css('background', backgroundAtr);
}
});
감사합니다. 그것이 바로 내가 찾는 것입니다. 그것은 여전히 일종의 뒤죽박죽이다. 내 코드에서 수행 할 수있는 최적화가 더 있습니까? – Jon
Nm. 'background' 속성을 수정하는 대신'background-position-x'를 수정했습니다. – Jon