jQuery로 자동로드에 DIV를 얻습니다
-
06-07-2019 - |
문제
ID 속성을 변경하려는 이전의 시도를 긁었습니다. 요청 === 0이라면 자동로드 아래 내용을 자동로드 할 수있는 방법이 있습니까? 클릭 함수를 갖지 않고.
<script language="javascript">
var requests = 10;
function request(self)
{if(self.href != "#")
requests -= 1;
if(requests === 0)
var pageid = function () {
var thisID = null;
$('#step').click(function () {
thisID = this.id;
$('#content').animate({
height: getPageHeight()
},
700, function () {
$('#next-page').fadeIn(500);
$('#content-' + thisID).fadeIn(500, function () {});
});
return false;
});
};
$(window).load(pageid);
function getPageHeight() {
var windowHeight;
if (self.innerHeight) windowHeight = self.innerHeight;
else if (document.documentElement && document.documentElement.clientHeight) windowHeight = document.documentElement.clientHeight;
else if (document.body) windowHeight = document.body.clientHeight;
return windowHeight;
}}
</script>
해결책
여기에서 모든 코드를 래핑하십시오.
$(document).ready(function() {
// your code
}
페이지가로드 될 때 코드가 실행되면 원하는 콘텐츠를 사용할 준비가되지 않은 상황 (아직 다운로드되지 않을 수도 있음). 따라서 코드를 실행하기 전에 페이지가로드 될 때까지 기다리십시오.
편집하다
"$ (창) .load (pageid);"일 수 있습니다. 잘못된 코드이지만, 일이 여전히 작동하지 않으면 목표에 대해 더 구체적이어야합니다.
이 같은:
<script language="javascript">
var requests = 10;
$(document).ready(function() {
// Your code here
// $(window).load(pageid);
});
function request(self)
{if(self.href != "#")
requests -= 1;
if(requests === 0)
var pageid = function () {
var thisID = null;
$('#step').click(function () {
thisID = this.id;
$('#content').animate({
height: getPageHeight()
},
700, function () {
$('#next-page').fadeIn(500);
$('#content-' + thisID).fadeIn(500, function () {});
});
return false;
});
};
function getPageHeight() {
var windowHeight;
if (self.innerHeight) windowHeight = self.innerHeight;
else if (document.documentElement && document.documentElement.clientHeight) windowHeight = document.documentElement.clientHeight;
else if (document.body) windowHeight = document.body.clientHeight;
return windowHeight;
}}
</script>
다른 팁
다음과 같은로드 이벤트에서 익명 기능을 사용하십시오.
$(window).load(function() {
if(requests === 0)
pageid(); // or whatever you need
});
그러나 먼저 제거하십시오 if(requests === 0)
코드에서 조건.
제휴하지 않습니다 StackOverflow