admin管理员组文章数量:1024615
Morning Guys,
Ok so I am using Bootstrap 3 to build my website - wanting to polish it off using the scrollTop smooth scroll on anchored tags. Cannot get it to work for the life of me.
So here is my code:
<script type="text/javascript" src="js/animate.js"></script>
<body>
<div id='imgDiv'>
<div class="container">
<center>
<a href="#imgDiv2"><h2>my link</h2></a>
</center>
</div>
</div>
<a href="">
<div id='imgDiv2'></div>
some content here
</div>
</div>
</div>
</div>
<script src=".11.0/jquery.min.js"></script>
<script src="js/bootstrap.js"></script>
This is the script inside animate.js
// JavaScript Document
$(document).ready(function() {
$('a[href^="#"]').click(function() {
var target = $(this.hash);
if (target.length == 0) target = $('a[name="' + this.hash.substr(1) + '"]');
if (target.length == 0) target = $('html');
$('html, body').animate({ scrollTop: target.offset().top }, 500);
return false;
});
});
So it does anchor to the div id named imgDiv2 but not using the smooth scrolling animation, any thoughts?
Morning Guys,
Ok so I am using Bootstrap 3 to build my website - wanting to polish it off using the scrollTop smooth scroll on anchored tags. Cannot get it to work for the life of me.
So here is my code:
<script type="text/javascript" src="js/animate.js"></script>
<body>
<div id='imgDiv'>
<div class="container">
<center>
<a href="#imgDiv2"><h2>my link</h2></a>
</center>
</div>
</div>
<a href="">
<div id='imgDiv2'></div>
some content here
</div>
</div>
</div>
</div>
<script src="http://ajax.googleapis./ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="js/bootstrap.js"></script>
This is the script inside animate.js
// JavaScript Document
$(document).ready(function() {
$('a[href^="#"]').click(function() {
var target = $(this.hash);
if (target.length == 0) target = $('a[name="' + this.hash.substr(1) + '"]');
if (target.length == 0) target = $('html');
$('html, body').animate({ scrollTop: target.offset().top }, 500);
return false;
});
});
So it does anchor to the div id named imgDiv2 but not using the smooth scrolling animation, any thoughts?
Share Improve this question edited May 18, 2014 at 10:40 creimers 5,3034 gold badges36 silver badges56 bronze badges asked May 9, 2014 at 8:11 user3520443user3520443 2792 silver badges12 bronze badges 1- 1 First load Jquery, than the plug-ins that require Jquery. They work with each other – Dorvalla Commented May 9, 2014 at 8:15
1 Answer
Reset to default 4You need to include animate.js
after jQuery since your jQuery code inside animate.js
require jQuery core library to work:
<script src="http://ajax.googleapis./ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="js/bootstrap.js"></script>
<script type="text/javascript" src="js/animate.js"></script>
Morning Guys,
Ok so I am using Bootstrap 3 to build my website - wanting to polish it off using the scrollTop smooth scroll on anchored tags. Cannot get it to work for the life of me.
So here is my code:
<script type="text/javascript" src="js/animate.js"></script>
<body>
<div id='imgDiv'>
<div class="container">
<center>
<a href="#imgDiv2"><h2>my link</h2></a>
</center>
</div>
</div>
<a href="">
<div id='imgDiv2'></div>
some content here
</div>
</div>
</div>
</div>
<script src=".11.0/jquery.min.js"></script>
<script src="js/bootstrap.js"></script>
This is the script inside animate.js
// JavaScript Document
$(document).ready(function() {
$('a[href^="#"]').click(function() {
var target = $(this.hash);
if (target.length == 0) target = $('a[name="' + this.hash.substr(1) + '"]');
if (target.length == 0) target = $('html');
$('html, body').animate({ scrollTop: target.offset().top }, 500);
return false;
});
});
So it does anchor to the div id named imgDiv2 but not using the smooth scrolling animation, any thoughts?
Morning Guys,
Ok so I am using Bootstrap 3 to build my website - wanting to polish it off using the scrollTop smooth scroll on anchored tags. Cannot get it to work for the life of me.
So here is my code:
<script type="text/javascript" src="js/animate.js"></script>
<body>
<div id='imgDiv'>
<div class="container">
<center>
<a href="#imgDiv2"><h2>my link</h2></a>
</center>
</div>
</div>
<a href="">
<div id='imgDiv2'></div>
some content here
</div>
</div>
</div>
</div>
<script src="http://ajax.googleapis./ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="js/bootstrap.js"></script>
This is the script inside animate.js
// JavaScript Document
$(document).ready(function() {
$('a[href^="#"]').click(function() {
var target = $(this.hash);
if (target.length == 0) target = $('a[name="' + this.hash.substr(1) + '"]');
if (target.length == 0) target = $('html');
$('html, body').animate({ scrollTop: target.offset().top }, 500);
return false;
});
});
So it does anchor to the div id named imgDiv2 but not using the smooth scrolling animation, any thoughts?
Share Improve this question edited May 18, 2014 at 10:40 creimers 5,3034 gold badges36 silver badges56 bronze badges asked May 9, 2014 at 8:11 user3520443user3520443 2792 silver badges12 bronze badges 1- 1 First load Jquery, than the plug-ins that require Jquery. They work with each other – Dorvalla Commented May 9, 2014 at 8:15
1 Answer
Reset to default 4You need to include animate.js
after jQuery since your jQuery code inside animate.js
require jQuery core library to work:
<script src="http://ajax.googleapis./ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="js/bootstrap.js"></script>
<script type="text/javascript" src="js/animate.js"></script>
本文标签: javascriptscrollTop anchor linking in Bootstrap 3Stack Overflow
版权声明:本文标题:javascript - scrollTop anchor linking in Bootstrap 3 - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745601873a2158503.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论