본문에 id 구성 요소 - 홈페이지가있는 홈페이지가 있습니다. 이 페이지는 바닥 글, 탐색 및 다른 요소에 몇 가지 애니메이션이 있습니다. 이 요소들은 다른 모든 페이지에서 같은 이름을가집니다.특정 div에서만 jQuery 코드를 실행하십시오
요소가 # component-homepage에있을 때 jQuery 코드를 실행하고 싶습니다. (js 파일에는이 코드가 더 많이 포함됩니다).
$('#component-homepage').ready(function(){
// code
});
그러나이 작동하지 않습니다
// This could should be on all the pages
$("nav li:last-child").addClass('last-child');
// This code should only be used when the id #component-homepage is in the body
// Homepage navigatie fadeIn + contentblok animatie
$('#content_home').hide();
$('nav').hide().fadeIn(1200, function(){
var result = $("#content_home").outerHeight();
$('#content_home_container').css({"margin-top": -Math.abs(result), "height": (result)});
$('#content_home').css({"margin-top": (result),"display":"block"}).animate({marginTop: '0px'},1000);
});
// Homepage navigatie animatie + url click event
$('nav a').click(function(event){
event.preventDefault();
var href = this.href;
$('nav').animate({
marginTop: '-635px'},
1000,
function(){
window.location = href;
});
$('footer').fadeOut(200);
});
나는이의 코드가 wrappen했습니다.
우수. Excactly 내가 뭘 찾고 있었습니까. 코드 행은 다음을 수행합니다. 코드가 실행되는 경우 # 구성 요소 홈페이지에 html이 있는지 확인합니다. 그렇지 않으면 실행하지 않습니다. 이 올바른지? 몇 분 안에 정확한 답을 알려 드리겠습니다. –
아님 - # component-homepage라는 ID를 가진 요소가 있는지 확인하고 코드가 실행 중인지 확인합니다. 그렇지 않으면 코드가 실행됩니다. 이것이 원하는 것입니다. – Bill
[jlery API 설명서 .length] (http://api.jquery.com/length/) – Bill