1
하나의 클릭 이벤트에서 2 개의 함수를 실행해야하며 중첩하는 방법을 알 수 없습니다.함수 jquery 내의 함수
현재 둘 다 별도로 실행되지만 함께 사용하면 작동하지 않습니다.> 저는 Jquery로 잠깐 들르려고합니다.
이 기능은 클릭 후 메뉴를 닫습니다.
$(document).on('click','.navbar-collapse.in',function(e) {
if($(e.target).is('a')) {
$(this).collapse('toggle');
}
});
그리고이 함수는 내 특정 앵커로 스크롤합니다.
function scrollToAnchor() {
if($(".jquery-anchor").length > 0 && document.URL.indexOf("#") >= 0){
var anchor = document.URL.split("#")[1];
$(".jquery-anchor").each(function() {
if($(this).attr("name") == anchor) {
$("html,body").animate({
scrollTop: $(this).offset().top - 50},
'slow');
}
});
}
}
$(function() {
$("a[href*='#JDG']:not([href='#'])").click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
&& location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top - 30 //offsets for fixed header
}, 1000);
return false;
}
}
});
//Executed on page load with URL containing an anchor tag.
if($(location.href.split("#")[1])) {
var target = $('#'+location.href.split("#")[1]);
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top - 30 //offset height of header here too.
}, 1000);
return false;
}
}
});
아래의 click 이벤트에서 top 함수를 배치하는 방법과 위치를 파악할 수 없습니다. 가능한가요? 두 기능에서
$("a[href*='#JDG']:not([href='#'])").click(function() {
});
한 OMG는 간단 ....... 당신이 재스퍼 – Torads
+1 당신은 왜 다른 사람의 이익을 위해 설명 할 감사이었다 @JasperSeinhorst? – PeterKA
false를 반환하면 다른 핸들러가 실행되지 않습니다. –