Javascript 未捕获引用错误:未定义scrollToM
我正在一个网站上使用Karl Swedberg的Smooth Scroll v1.4.5。只有这个版本的平滑滚动有效,尽管它有效,但我得到的错误是没有定义scrollToM 此外,每当我使用脚本导航到特定页面时,它都会不断添加Javascript 未捕获引用错误:未定义scrollToM,javascript,jquery,smooth-scrolling,Javascript,Jquery,Smooth Scrolling,我正在一个网站上使用Karl Swedberg的Smooth Scroll v1.4.5。只有这个版本的平滑滚动有效,尽管它有效,但我得到的错误是没有定义scrollToM 此外,每当我使用脚本导航到特定页面时,它都会不断添加 <div style="height: 101%; overflow: hidden;"></div> 而且页面大小继续增长,导致更多问题 以下是脚本: <script type="text/javascript" src="js/jq
<div style="height: 101%; overflow: hidden;"></div>
而且页面大小继续增长,导致更多问题
以下是脚本:
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".contactLink").click(function(){
if ($("#contactForm").is(":hidden")){
$("#contactForm").slideDown("slow");
}
else{
$("#contactForm").slideUp("slow");
}
});
});
function closeForm(){
$("#messageSent").show("slow");
setTimeout('$("#messageSent").hide();$("#contactForm").slideUp("slow")', 2000);
}
$(document).ready(function() {
function filterPath(string) {
return string
.replace(/^\//,'')
.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
.replace(/\/$/,'');
}
$('a[href*=#]').each(function() {
if ( filterPath(location.pathname) == filterPath(this.pathname)
&& location.hostname == this.hostname
&& this.hash.replace(/#/,'') ) {
var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) +']');
var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
if ($target) {
var targetOffset = $target.offset().top;
$(this).click(function() {
$('html, body').animate({scrollTop: targetOffset}, 1000);
var d = document.createElement("div");
d.style.height = "101%";
d.style.overflow = "hidden";
document.body.appendChild(d);
window.scrollTo(0,scrollToM);
setTimeout(function() {
d.parentNode.removeChild(d);
}, 10);
return false;
});
}
}
});
});
/*! Smooth Scroll - v1.4.5 - 2012-07-22
* Copyright (c) 2012 Karl Swedberg; Licensed MIT, GPL */
</script>
$(文档).ready(函数(){
$(“.contactLink”)。单击(函数(){
如果($(“#contactForm”)。是(“:隐藏”)){
$(“#contactForm”)。向下滑动(“慢速”);
}
否则{
$(“#contactForm”).slideUp(“slow”);
}
});
});
函数closeForm(){
$(“#messageSent”).show(“slow”);
setTimeout(“$”(“#messageSent”).hide();$(“#contactForm”).slideUp(“slow”)”,2000);
}
$(文档).ready(函数(){
函数筛选器路径(字符串){
返回字符串
.替换(/^\/,'')
.replace(/(索引|默认值)。[a-zA-Z]{3,4}$/,“”)
.替换(/\/$/,'');
}
$('a[href*=#]')。每个(函数(){
if(filterPath(location.pathname)==filterPath(this.pathname)
&&location.hostname==this.hostname
&&this.hash.replace(/#/,''){
var$targetId=$(this.hash),$targetAnchor=$('[name='+this.hash.slice(1)+']);
var$target=$targetId.length?$targetId:$targetAnchor.length?$targetAnchor:false;
如果(目标美元){
var targetOffset=$target.offset().top;
$(此)。单击(函数(){
$('html,body').animate({scrollTop:targetOffset},1000);
var d=document.createElement(“div”);
d、 style.height=“101%”;
d、 style.overflow=“隐藏”;
文件.正文.附件(d);
scrollTo(0,scrollToM);
setTimeout(函数(){
d、 parentNode.removeChild(d);
}, 10);
返回false;
});
}
}
});
});
/*! 平滑滚动-v1.4.5-2012-07-22
*版权所有(c)2012卡尔·斯维德伯格;特许麻省理工学院*/
这里还有网站链接。嗯,它似乎没有定义。在调用.scrollTo
时使用了它,但您发布的内容中没有声明。好的,我让它工作了。[还没有在网站上直播]我愚蠢地使用了一个过时的jquery.min文件。在使用Github并查看SmoothSlide版本后,我意识到该脚本与另一个版本的JQuery[1.5.2]链接兼容:“好的,太好了。”。但是,该版本(1.5.2)已经很旧了。无论如何,在JQuery方面没有受过很好的教育:/