我正在使用 Ariel Flesler 的 scrollTo 插件和引导程序。它看起来很简单,但我无法让它工作。我想单击按钮,它会平滑滚动到相应的 ID。这是一个按钮的示例。
这是html:
<a class="btn btn-primary" href="#faqs"></i>FAQS</a>
<div class="id="faqs">
<script src="js/jquery.scrollTo-1.4.3.1-min.js"></script>
Qn。1 jQuery 应该是什么才能使我的所有按钮都能正常工作?
Qn。2顺便说一句,我从 twitter bootstrap 的网站“application.js”中偷了东西,但并不理解它们的含义,只是为了让我的网站正常工作。你能解释一下这些代码的含义吗?
//Is this bit of code the convention to add to the start of every jQuery doc?
!function ($) {
$(function(){
var $window = $(window)
//What does this do?
$('[href^=#]').click(function (e) {
e.preventDefault()
})
//This code scrolls smoothly to top, however it only works when the code below is present. Why?
$("a[href='#top']").click(function() {
$("html, body").animate({ scrollTop: 0 }, "slow");
return false;
})
// This is the weird bit of code I don't understand. Without this, my scrollTop doesn't work. Could this bit of code also interfere with scrollTo's plugin? I assume it will...
$('.download-btn .btn').on('click', function () {
var css = $("#components.download input:checked")
.map(function () { return this.value })
.toArray()
, js = $("#plugins.download input:checked")
.map(function () { return this.value })
.toArray()
, vars = {}
, img = ['glyphicons-halflings.png', 'glyphicons-halflings-white.png']
感谢您回答我所有的问题,非常感谢。