0
내 페이지 내용을 바꾸기 위해 AJAX 호출을 수행하고 있습니다. 불행히도 내 전체 페이지의 스타일을 엉망으로 만드는 오래된 클래스를 가지고 내 전체 body
요소를 보존합니다.전체 본문 요소를 (클래스 및 ID와 같은 속성과 함께) 바꿉니다.
내가 완전히하지 않는 누군가 다른 사람의 코드를 사용하고 이해 :
function loadNewContent(url, bool) {
url = ('' == url) ? window.location.pathname : url;
var newSection = 'cd-'+url.replace('.html', '');
var section = $('<div class="cd-main-content '+newSection+'"></div>');
section.load(url+' .cd-main-content > *', function(event){
// load new content and replace <main> content with the new one
$('main').html(section);
//if browser doesn't support CSS transitions - dont wait for the end of transitions
var delay = (transitionsSupported()) ? 1200 : 0;
setTimeout(function(){
//wait for the end of the transition on the loading bar before revealing the new content
(section.hasClass('cd-about')) ? $('body').addClass('cd-about') : $('body').removeClass('cd-about');
$('body').removeClass('page-is-changing');
$('.cd-loading-bar').one('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend', function(){
isAnimating = false;
$('.cd-loading-bar').off('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend');
});
if(!transitionsSupported()) isAnimating = false;
}, delay);
if(url!=window.location && bool){
//add the new page to the window.history
//if the new page was triggered by a 'popstate' event, don't add it
window.history.pushState({path: url},'',url);
}
});
}
이 완전히 이전 body
요소를 파괴하고 그것을 대체 할 수 있도록,이 코드 조각을 수정하는 것이 가능 새로운 것? 또는 적어도 이전 class
body 속성을 새 것으로 대체 하시겠습니까?
Tijmen은별로 효과가 없습니다. 이 줄에서'main' 만'body'로 바꾼다면, 오래된 몸체는 바뀔 것입니다, 사실, 나는 새로운 몸체를 어디에도 갖지 않을 것입니다. 그리고 내 페이지가 고장났다. –
흠, true. 나는 잠시 밖에 나가기를 원하지만, 내가 돌아 왔을 때 나는 더 깊이 들여다 볼 것이다. – Tijmen