Php 单击按钮滚动到特定div?
各位好, 我是php新手。我想向下滚动到我的div,点击按钮。请帮我看看我是怎么做的。当我点击按钮时,滚动条会稍微移动到我的div 我正在使用这个代码Php 单击按钮滚动到特定div?,php,jquery,Php,Jquery,各位好, 我是php新手。我想向下滚动到我的div,点击按钮。请帮我看看我是怎么做的。当我点击按钮时,滚动条会稍微移动到我的div 我正在使用这个代码 <script type="text/javascript"> $(document).ready(function() { $('#scroll').click(function() { $.scrollTo($('#res'), 500); }) }); </script>
<script type="text/javascript">
$(document).ready(function() {
$('#scroll').click(function() {
$.scrollTo($('#res'), 500);
})
});
</script>
<input type="button" value="Scroll" id="scroll" />
<div id="data">one big idea.
<div class="res" id="res">
<h2>RESULT</h2>
one big idea..
</div>
<p>one big idea.</p>
</div>
$(文档).ready(函数(){
$(“#滚动”)。单击(函数(){
$.scrollTo($('res'),500);
})
});
一个好主意。
结果
一个好主意。。
一个好主意
提前谢谢
$('#scroll').click(function() {
$('html,body').animate({'scrollTop':$('#res').position().top}, 500);
});
对于标签
对于标签..我使用这个
// [a] obj to scroll to, mandatory, like, '#id' or '.class'
// [c] miliseconds, default 1 sec. if not set
// [b] offset from top, default 0 if not set
function sTo(a,c,b){
if(typeof(a)=="undefined")return;
c=typeof(c)!="undefined"?c:1000;
b=typeof(b)!="undefined"?b:0;
jQuery("html,body").stop(true,true).animate({scrollTop:jQuery(a).offset().top+b},c,function(){
// if you want a callback function, call it here
});
}
那么,就这样称呼它:
<input type="button" value="Scroll" id="scroll" onclick="sTo('#res',500,50)"/>
我用这个
// [a] obj to scroll to, mandatory, like, '#id' or '.class'
// [c] miliseconds, default 1 sec. if not set
// [b] offset from top, default 0 if not set
function sTo(a,c,b){
if(typeof(a)=="undefined")return;
c=typeof(c)!="undefined"?c:1000;
b=typeof(b)!="undefined"?b:0;
jQuery("html,body").stop(true,true).animate({scrollTop:jQuery(a).offset().top+b},c,function(){
// if you want a callback function, call it here
});
}
那么,就这样称呼它:
<input type="button" value="Scroll" id="scroll" onclick="sTo('#res',500,50)"/>
滚动到
不是现有的jquery函数
您可以使用滚动顶
和动画
的组合来模拟它。大概是这样的:
$(document).ready(function() {
$("#scroll").click(function() {
$('html, body').animate({
scrollTop: $("#res").offset().top
}, 2000);
});
});
滚动到
不是现有的jquery函数
您可以使用滚动顶
和动画
的组合来模拟它。大概是这样的:
$(document).ready(function() {
$("#scroll").click(function() {
$('html, body').animate({
scrollTop: $("#res").offset().top
}, 2000);
});
});
为什么同时使用html和正文?@Itay我使用$('html,正文')实现跨浏览器兼容性为什么同时使用html和正文?@Itay我使用$('html,正文'))为了实现跨浏览器兼容性,我有一个jquery滑块,它在我的特定分区上运行。我想向下滚动到该滚动条,而不是我的页面滚动有一个jquery滑块,它在我的特定分区上运行。我想向下滚动到该滚动条,而不是我的页面滚动条