替换<;a>;与<;标签>;Jquery动画滚动条

替换<;a>;与<;标签>;Jquery动画滚动条,jquery,html,jquery-animate,smooth-scrolling,Jquery,Html,Jquery Animate,Smooth Scrolling,我对JQuery真的很陌生,所以。我在这里总是能找到很大的帮助,但现在我真的需要一些帮助 我在这里发现了这个链接,它非常棒,直到我尝试用标签替换它。我试了几样东西,找了不少。我希望我没有错过什么明显的东西。。不管怎样,这是代码 <head> <script type="text/javascript"> $('label').click(function(){ $('html, body').animate({ scrollTop: $( $.attr(this, 'on

我对JQuery真的很陌生,所以。我在这里总是能找到很大的帮助,但现在我真的需要一些帮助

我在这里发现了这个链接,它非常棒,直到我尝试用
标签替换它。我试了几样东西,找了不少。我希望我没有错过什么明显的东西。。不管怎样,这是代码

<head>
<script type="text/javascript">
$('label').click(function(){
$('html, body').animate({
scrollTop: $( $.attr(this, 'onclick') ).offset().top
}, 500);
return false;
}); 
</script>
</head>

<body>

<!--(START) THIS IS THE LABEL I WANT TO CLICK (START)-->
<div id="top">
    <input type="checkbox" class="toggle" id="button">
        <label class="linkbutton" onclick="window.location.href='#SCROLL'" for="button">
            <h2>Click This Text = Scroll Down</h2>
        </label>
</div>
<!--(START) END OF LABEL (START)-->

<div id="left"></div>
<div id="mid-container">

<!--(END) WHERE I WANT TO GO SMOOTHLY(END)-->
<div class="mid">
    <div class="section"><label id="SCROLL"></label>
        <h2>This is the section I want to go to.... SMOOTHLY</h2>
    </div>
</div>
<!--(END) WHERE I WANT TO GO SMOOTHLY (END)-->

</body>
</html>

$('label')。单击(函数(){
$('html,body')。设置动画({
scrollTop:$($.attr(这是'onclick')).offset().top
}, 500);
返回false;
}); 
单击此文本=向下滚动
这是我想去的部分。。。。平稳地
标签指示我要去的地方,但没有任何平滑度。
感谢您的帮助。

您可以使用自定义的
数据-
属性来保存要滚动到的
href
值:

HTML

<div id="top">
   <input type="checkbox" class="toggle" id="button">
   <label class="linkbutton" data-href="#SCROLL" for="button">
     <h2>Click This Text = Scroll Down</h2>
   </label>
</div>
<!--(START) END OF LABEL (START)-->

<div id="left"></div>
<div id="mid-container">

 <div class="mid">
    <div class="section"><label id="SCROLL"></label>
         <h2>This is the section I want to go to.... SMOOTHLY</h2>
    </div>
 </div>

您可以使用自定义的
数据-
属性来保存要滚动到的
href
值:

HTML

<div id="top">
   <input type="checkbox" class="toggle" id="button">
   <label class="linkbutton" data-href="#SCROLL" for="button">
     <h2>Click This Text = Scroll Down</h2>
   </label>
</div>
<!--(START) END OF LABEL (START)-->

<div id="left"></div>
<div id="mid-container">

 <div class="mid">
    <div class="section"><label id="SCROLL"></label>
         <h2>This is the section I want to go to.... SMOOTHLY</h2>
    </div>
 </div>

HTML

<label class="linkbutton" data-href="#SCROLL" for="button">
HTML


非常感谢。那正是我想要的。非常感谢,非常感谢。那正是我想要的。非常感谢。
$('label').click(function(){
    $('html, body').animate({
        scrollTop: $( $(this).data('href') ).offset().top
    }, 500);
});