【发布时间】:2016-06-28 01:39:39
【问题描述】:
我开始使用mark.js 实时搜索插件,我能够对其进行修改以自动滚动到页面上正在搜索的文本部分。
像这样:
SEARCH BOX |_jklmno____| <-- User searches here
123
456
789
abcde
fghi
jklmno <--- Then the page will automatically scroll and stop here.
pqrst
-> 完成,找到了文本
代码有效,如何构建一个按钮,当提交时,页面会跳转到下一个结果?
我尝试在提交表单时使用它跳转到下一个结果:
$('html,body').animate({scrollTop: mark.eq(index).offset().top}, 500);
}
这也是:
else if ('mark[data-markjs]').live("submit", function(e) {
e.mark();
$('html,body').animate(
{scrollTop: mark.offset().top -100}
, 200);
});
但是没有用。
这是working fiddle **(要查看搜索字段,您必须稍微滚动一下结果选项卡)
这里是 jQuery:
$.noConflict()
jQuery(function($) {
var mark = function() {
// Read the keyword
var keyword = $("input[name='keyword']").val();
// Determine selected options
var options = {
"filter": function(node, term, counter, totalCounter){
if(term === keyword && counter >= 1){
return false;
} else {
return true;
}
},
done: function() {
var mark = $('mark[data-markjs]');
if (mark.length) {
$('html,body').animate({scrollTop: mark.eq(index).offset().top}, 500);
}
/*
else if ('mark[data-markjs]').live("submit", function(e) {
e.mark();
$('html,body').animate(
{scrollTop: mark.offset().top -100}
, 200);
});
*/
}
};
$("input[name='opt[]']").each(function() {
options[$(this).val()] = $(this).is(":checked"); });
// Mark the keyword inside the context
$(".context").unmark();
$(".context").mark(keyword, options);
};
$("input[name='keyword']").on("keyup", mark);
$("input[type='checkbox']").on("change", mark);
$("input[name='keyword']").on("submit", mark);
});
【问题讨论】:
-
所以没有解决办法?
标签: javascript jquery jquery-ui jquery-plugins