정말이 질문에 대답했다.
당신이해야 할 모든
이
<a href="#bottom">scroll to bottom</a>
<p id="bottom">bottom</p>
같은 일반 앵커 링크는 다음이 자바 스크립트 코드를 추가하고 당신은 너무 모바일
<script>
$(function() {
function filterPath(string) {
return string
.replace(/^\//,'')
.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
.replace(/\/$/,'');
}
var locationPath = filterPath(location.pathname);
var scrollElem = scrollableElement('html', 'body');
// Any links with hash tags in them (can't do ^= because of fully qualified URL potential)
$('a[href*=#]').each(function() {
// Ensure it's a same-page link
var thisPath = filterPath(this.pathname) || locationPath;
if ( locationPath == thisPath
&& (location.hostname == this.hostname || !this.hostname)
&& this.hash.replace(/#/,'')) {
// Ensure target exists
var $target = $(this.hash), target = this.hash;
if (target) {
// Find location of target
var targetOffset = $target.offset().top;
$(this).click(function(event) {
// Prevent jump-down
event.preventDefault();
// Animate to target
$(scrollElem).animate({scrollTop: targetOffset}, 400, function() {
// Set hash in URL after animation successful
location.hash = target;
});
});
}
}
});
// Use the first element that is "scrollable" (cross-browser fix?)
function scrollableElement(els) {
for (var i = 0, argLength = arguments.length; i <argLength; i++) {
var el = arguments[i],
$scrollElement = $(el);
if ($scrollElement.scrollTop()> 0) {
return el;
} else {
$scrollElement.scrollTop(1);
var isScrollable = $scrollElement.scrollTop()> 0;
$scrollElement.scrollTop(0);
if (isScrollable) {
return el;
}
}
}
return [];
}
});
</script>
임, 아무것도 변경 자바 스크립트 의견을보실해야하는 경우 임베디드 코드와 나는 그것을 바꿀 수 없다 ...하지만 당신은 내가 무슨 뜻인지 확신한다. –
[jQuery.ScrollTo] (http://flesler.blogspot.com/2007/10/jqueryscrollto.html) –
어떻게 사용합니까? onclick 함수로이 id를 넣으십시오. onclck = "jQuery.ScrollTo (bottom)" –