[英]Jquery scroll to closest element with .class
问题
我有我的html页面,我正在使用由我创建的搜索引擎,例如“ Ctrl + F”,我集成了一个jquery插件,该插件突出显示了我搜索到的所有结果,并将类“ .highlight”添加到了它的元素中突出显示,每当我按搜索按钮时,我想在它们之间滚动。
我试过了,但是没有用:
$(document).ready(function () {
$("#btnSearch").on("click", function () {
$('html, body').animate({
'scrollTop': $(this).closest(".highlight").position().top
});
});
});
也许这可以帮助您...
$(document).ready(function () {
$("#btnSearch").on("click", function () {
$('html, body').animate({
'scrollTop': $(this).closest(".highlight").parent().scrollTop()+ $(this).closest(".highlight").offset().top - $(this).closest(".highlight").parent().offset().top,
});
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.