[英]how to scroll to a specific div when a radio button is clicked/changed
I am trying to scroll the page to "#Table_Details" using the scroll plug in. But i can't seem to get it working. 我正在尝试使用滚动插件将页面滚动到“#Table_Details”。但我似乎无法让它工作。
When i click/change the radio(.ModemsSelect) button the page scrolls to the location of the radio button i just clicked instead of scrolling down the page where my table("#table_Details") is located. 当我单击/更改收音机(.ModemsSelect)按钮时,页面滚动到我刚刚单击的单选按钮的位置,而不是向下滚动我的表(“#table_Details”)所在的页面。 I am not sure if i am doing this right or what is going on.
我不确定我是做对了还是做了什么。
$(".ModemsSelect,.ServicesSelect").change(function (e) {
var data = $("#" + this.value).serialize();
var request = $.ajax({
url: "classes/sCart.php?action=add",
type: "POST",
data: data,
dataType: "html",
radioButton: $(this).attr('class')
});
request.success(function (data) {
//$(".in_cart").html("");//clear last item selected
console.log("extra item added to cart");
refreshCart();
if (this.radioButton == "ModemsSelect") {
$.scrollTo($('#Table_Details'));
$("#icon_check_modem").html("");
$("#icon_check_modem").html("<img src=\"../img/check_icon.png\">");
$('.Modem_buttonNext').button("enable");
} else if (this.radioButton == "ServicesSelect") {
$("#icon_check_Installtype").html("");
$("#icon_check_Installtype").html("<img src=\"../img/check_icon.png\">");
$(".install_buttonNext").button("enable");
} else {
}
});
});
Any help is appreciated. 任何帮助表示赞赏。 thank you.
谢谢。
Try doing it this 试试这个
$('html, body').animate({
scrollTop: $("#Table_Details").offset().top
}, 2000);
Instead of this: 而不是这个:
$.scrollTo($('#Table_Details'));
I got the code from this article: SMOOTHLY SCROLL TO AN ELEMENT WITHOUT A JQUERY PLUGIN 我从这篇文章中得到了代码: 平稳地滚动到没有JQUERY PLUGIN的元素
working fiddle http://jsfiddle.net/ePstY/ 工作小提琴http://jsfiddle.net/ePstY/
You must replace this: 你必须替换这个:
$.scrollTo($('#Table_Details'));
with this: 有了这个:
$('html, body').animate({scrollTop:$('#Table_Details').position().top}, 'slow');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.