사용자가 페이드 인/페이드 아웃 메시지를 표시하는 코드 (스크립트 태그 내부)에서 내 함수를 호출 할 수있는 웹 응용 프로그램에 대한 메서드를 제공하려고합니다. 어떻게 해야할지 모르겠지만 시작 기준점이 없으면 DOM에서 내가 어디에 있는지 판단해야합니다.시작점이없는 부모 노드를 얻는 방법은 무엇입니까?
기능 :
function displayMessage(message) {
// Display a notification if the submission is successful.
$('<div class="save-alert">' + message + '</div>')
.insertAfter($('')) // Do not know how to know where to put the message.
.fadeIn('slow')
.animate({ opacity: 1.0 }, 2000)
.fadeOut('slow', function() {
$(this).remove();
});
}
html로 :
<!-- Some HTML -->
<div>
<script type="text/javascript">
displayMessage("My message.");
</script>
</div>
<!-- Some more HTML. -->
당신은 실제 스크립트 코드가 작성된 위치에 따라 컨텍스트를 결정하고 싶습니까? –
이와 비슷한 것 : http://stackoverflow.com/questions/210717/what-is-the-best-way-to-center-a-div-on-the-screen-using-jquery – jhartz
@Caspar - 예 . 나는 그것이 가능하다고 생각하지는 못했다.하지만 아무도 모른다면 그렇게 좋은 사람들이 될 것이라고 생각했다. 그래서 물어보기로했습니다. – JasCav