2012-05-06 2 views
1

jquery load()를 사용하여 내 웹 사이트의 모든 문서를 표시하고 있습니다. index.html을 파일에 내 스크립트는 home.html을jQuery 슬라이더가 처음으로 사이트를로드 할 때

$(document).ready(function() { 
//$(window).load(function() { 
    $('#slider').nivoSlider({effect:'fade', animSpeed:800, pauseTime:5000}); 
return false; 
    }); 

nivoslider에 대한 기본값은 (창) .load에서이

<script type="text/javascript"> 
    $(document).ready(function() { 
    $('#main-wrap').load("home.html"); 

    $('#home').click(function() { 
     $('#main-wrap').load("home.html"); 
     return false; 
    }); 

    $('#wilgoc').click(function() { 
     $('#main-wrap').load("wilgoc.html"); 
     return false; 
    }); 
etc... 

처럼 보이지만 내가 home.html을로드 할 때 작동하지 않습니다 두 번째로 ... 어떤 아이디어? 고맙습니다.

+0

시도 "준비"기능을 한 번 사용할 수 있습니다. 또는 $ (window) .ready()를 시도하십시오. – atilkan

답변

1

페이지는 (#slider 새로운 DOM 요소입니다) 동적으로로드 된 그래서

$('#home').click(function(e) { 
    e.preventDefault(); 
    $('#main-wrap').load("home.html", function(){ 
     $('#slider').nivoSlider({effect:'fade', animSpeed:800, pauseTime:5000}); 
    }); 
}); 

편집

을 작동하지 않습니다 :

이 home.html을에서 document.ready를 제거 index.html 파일을 home.html을로드 할 때마다 index.html 파일에 저장하고 콜백 함수 내에서 플러그인을 호출하십시오.

$(document).ready(function() { 

    $('#main-wrap').load("home.html", function(){ 
     $('#slider').nivoSlider({effect:'fade', animSpeed:800, pauseTime:5000}); 
    }); 

    $('#home').click(function(e) { 
     e.preventDefault(); 
     $('#main-wrap').load("home.html", function(){ 
      $('#slider').nivoSlider({effect:'fade', animSpeed:800, pauseTime:5000}); 
     }); 
    }); 
    ... 
    ... 
}); 

다른 전체 html 파일 (html로)을로드하지 않았는지 확인하십시오. head e.t.c 태그)를 div 안에 넣습니다.

당신은이 (각 라인을 대체) 시도 할 수

setTimeout(function(){ 
    $('#slider').nivoSlider({effect:'fade', animSpeed:800, pauseTime:5000}); 
}, 1000); 
+0

cllick 함수에는 아무런 문제가 없습니다. 첫 번째 사이트보기만으로 작동합니다. 처음로드 한 후에 슬라이더 선을 추가하려고했으나 결과가 없습니다. – sonia

+0

업데이트 확인 . –

+0

index.php 안에 다른 HTML 파일 (HTML 태그 포함)을로드하지 않았는지 확인하십시오. –

관련 문제