简体   繁体   English

单击按钮从上到下滚动到搜索的单词

[英]scroll to searched word from top to bottom with button click

I want to scroll to searched word one by one when I click down button. 当我点击向下按钮时,我想滚动浏览一个单词 Please see Fiddle for code implemented 请参阅Fiddle了解已实现的代码

$('#searchfor').keypress(function(){
  var page = $('#all_text');
  var pageText = page.text().replace("<span>","").replace("</span>");
  var searchedText = $('#searchfor').val();
  var theRegEx = new RegExp("("+searchedText+")", "igm");    
  var newHtml = pageText.replace(theRegEx ,"<span>$1</span>");
  page.html(newHtml);
});

see this example : http://jsfiddle.net/kevalbhatt18/ju6xxwvb/13/ 参见以下示例: http : //jsfiddle.net/kevalbhatt18/ju6xxwvb/13/

i used js from hear Search and Highlight in jQuery 我从jQuery中听到搜索和突出显示使用了js

and button login is wrriten 和按钮登录被写入

 var find = function(results, type, counter, adjPx, $el) { if (results.length > 0) { if (type === 'next') { if (counter > 0 && results.length == counter) { counter = 0; } } else if (type === 'prev') { if (counter < 0) { counter = results.length - 1; } else if (counter === results.length) { counter = counter - 2; } } results.removeClass("active"); $(results[counter]).addClass("active"); if ($el) { $('html,body').animate({ scrollTop: $(results[counter]).offset().top - adjPx }, 100); } else { $el.animate({ scrollTop: $(results[counter]).offset().top - adjPx }, 100); } counter = (type === 'prev') ? counter - 1 : counter + 1; } return counter; }; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM