Senior9324 (토론 | 기여) 편집 요약 없음 |
Senior9324 (토론 | 기여) 편집 요약 없음 |
||
23번째 줄: | 23번째 줄: | ||
if (!$(event.target).closest("#reference-drawer").length) { | if (!$(event.target).closest("#reference-drawer").length) { | ||
if ($(window).width() < 768) { | if ($(window).width() < 768) { | ||
$("#reference-drawer"). | $("#reference-drawer").slideUp("slow", function() { $(this).remove(); }); | ||
} else { | } else { | ||
$("#reference-drawer").animate({opacity: 0}, 100, function() { $(this).remove(); }); | $("#reference-drawer").animate({opacity: 0}, 100, function() { $(this).remove(); }); | ||
44번째 줄: | 44번째 줄: | ||
showDrawer(this.parentNode.href.split("#")[1], this.textContent); | showDrawer(this.parentNode.href.split("#")[1], this.textContent); | ||
if ($(window).width() < 768) { | if ($(window).width() < 768) { | ||
$("#reference-drawer").stop(). | $("#reference-drawer").stop().slideDown("slow"); | ||
} else { | } else { | ||
drawer.css({ top: ($(this).offset().top - drawer.outerHeight()), left: $(this).offset().left }); | drawer.css({ top: ($(this).offset().top - drawer.outerHeight()), left: $(this).offset().left }); |
2015년 6월 3일 (수) 17:56 판
var drawer, origin, content;
function showDrawer(id, name) {
origin.attr("href", "#" + id);
origin.attr("data-target", id);
origin.text(name);
content.html($("#" + id + " > .reference-text").html());
$(document.body).append(drawer);
}
$(document).ready(function($) {
/* create drawer */
drawer = $("<div></div>").attr("id", "reference-drawer");
origin = $("<a></a>")
.attr("id", "reference-origin")
.click(function() {
$('html, body').animate({scrollTop: ($("#" + $(this).attr("data-target")).offset().top - 60)}, 400);
});
content = $("<span></span>").attr("id", "reference-drawer-text");
drawer.append(origin);
drawer.append(content);
$(document).click(function(e) {
if (!$(event.target).closest("#reference-drawer").length) {
if ($(window).width() < 768) {
$("#reference-drawer").slideUp("slow", function() { $(this).remove(); });
} else {
$("#reference-drawer").animate({opacity: 0}, 100, function() { $(this).remove(); });
}
}
}).scroll(function(e) {
if ("ontouchstart" in window && !$(window).width() < 768) {
$("#reference-drawer").animate({marginTop: 0}, 250, function() { $(this).remove(); });
}
});
$(".reference a").each(function() {
var span = document.createElement("span");
span.className = "reference-hooker";
span.appendChild(this.childNodes[0]);
this.appendChild(span);
});
$(".reference-hooker").click(function(e) {
e.preventDefault();
e.stopPropagation();
showDrawer(this.parentNode.href.split("#")[1], this.textContent);
if ($(window).width() < 768) {
$("#reference-drawer").stop().slideDown("slow");
} else {
drawer.css({ top: ($(this).offset().top - drawer.outerHeight()), left: $(this).offset().left });
$("#reference-drawer").stop().animate({opacity: 1}, 100);
}
});
});