如何使用javascript和css将分割webview后的id跳转到页面

时间:2017-10-29 09:41:43

标签: javascript android html css webview

我有js和css将webivew拆分成页面并使用js方法setColumn导航。结果图如下: enter image description here

enter image description here

以下是代码:

<html>
<head>
<style type="text/css">
#container {
	background-color: yellow;
	overflow: hidden;
	width: 360px;
	height: 549px;
	margin-left: -9px;
	margin-top: -9px;
	padding: 0;
}
#content {
	position: relative;
	height: 30em;
	margin: 0;
	padding: 0;

	-moz-column-width: 360px;
	-webkit-column-width: 360px;
	column-width: 360px;

	-moz-column-gap: 0px;
	-webkit-column-gap: 0px;
	column-gap: 0px;
}
img{
	display:block;
	margin-left:auto,
	margin-right:auto,
	max-height:100% !important;
	max-width:100% !important;
	width: auto !important;
	height: auto !important;
}
</style>
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script>

var _column = 0;
var _columnCount = 0;
var _columnWidth = 360;
var _columnGap = 0;
$(function() {
	_columnCount = Math.floor($('#endMarker').position().left/(_columnWidth + _columnGap));
	console.log('There are ' + _columnCount + ' columns');

	setColumn = function(i) {
		_column = i;
		document.getElementById('content').style.left = -1 * _column * (_columnWidth + _columnGap);
		console.log('Set to column ' + _column);
		$('#page').html('Page ' + (_column+1) + ' of ' + (_columnCount+1));
	}
	$('#next').click(function() {
		if (_column==_columnCount) return;
		_column++;
		setColumn(_column);
	});
	$('#previous').click(function() {
		if (0==_column) return;
		_column--;
		setColumn(_column);
	});
	setColumn(0);
});

function previous(){
      if (0==_column) return;
		_column--;
		setColumn(_column);
		showCurrentProgress();
   }

function next(){
      if (_column==_columnCount) return;
		_column++;
		setColumn(_column);
		showCurrentProgress();
   }

function showCurrentProgress(){
	//alert("{"+"\"totalPage\":"+_columnCount+","+"\"currentPage\":"+_column+"}");
	anObj.show("{"+"\"totalPage\":"+_columnCount+","+"\"currentPage\":"+_column+"}");
}
</script>
</head>
<body>
<div id="container">
<div class="content" id="content">

 <p>
      Now, when I say that I am in the habit of going to sea whenever I begin to
      grow hazy about the eyes, and begin to be over conscious of my lungs, I do
      not mean to have it inferred that I ever go to sea as a passenger. For to
      go as a passenger you must needs have a purse, and a purse is but a rag
      unless you have something in it. Besides, passengers get sea-sick—grow
      quarrelsome—don't sleep of nights—do not enjoy themselves
      much, as a general thing;—no, I never go as a passenger; nor, though
      I am something of a salt, do I ever go to sea as a Commodore, or a
      Captain, or a Cook. I abandon the glory and distinction of such offices to
      those who like them. For my part, I abominate all honourable respectable
      toils, trials, and tribulations of every kind whatsoever. It is quite as
      much as I can do to take care of myself, without taking care of ships,
      barques, brigs, schooners, and what not. And as for going as cook,—though
      I confess there is considerable glory in that, a cook being a sort of
      officer on ship-board—yet, somehow, I never fancied broiling fowls;—though
      once broiled, judiciously buttered, and judgmatically salted and peppered,
      there is no one who will speak more respectfully, not to say
      reverentially, of a broiled fowl than I will. It is out of the idolatrous
      dotings of the old Egyptians upon broiled ibis and roasted river horse,
      that you see the mummies of those creatures in their huge bake-houses the
      pyramids.
    </p>

    <p>
      No, when I go to sea, I go as a simple sailor, right before the mast,
      plumb down into the forecastle, aloft there to the royal mast-head. True,
      they rather order me about some, and make me jump from spar to spar, like
      a grasshopper in a May meadow. And at first, this sort of thing is
      unpleasant enough. It touches one's sense of honour, particularly if you
      come of an old established family in the land, the Van Rensselaers, or
      Randolphs, or Hardicanutes. And more than all, if just previous to putting
      your hand into the tar-pot, you have been lording it as a country
      schoolmaster, making the tallest boys stand in awe of you. The transition
      is a keen one, I assure you, from a schoolmaster to a sailor, and requires
      a strong decoction of Seneca and the Stoics to enable you to grin and bear
      it. But even this wears off in time.
    </p>

    <h2 id="sigil_toc_id_10">Section Ten</h2>
    <p>
      What of it, if some old hunks of a sea-captain orders me to get a broom
      and sweep down the decks? What does that indignity amount to, weighed, I
      mean, in the scales of the New Testament? Do you think the archangel
      Gabriel thinks anything the less of me, because I promptly and
      respectfully obey that old hunks in that particular instance? Who ain't a
      slave? Tell me that. Well, then, however the old sea-captains may order me
      about—however they may thump and punch me about, I have the
      satisfaction of knowing that it is all right; that everybody else is one
      way or other served in much the same way—either in a physical or
      metaphysical point of view, that is; and so the universal thump is passed
      round, and all hands should rub each other's shoulder-blades, and be
      content.
    </p>

    <span id="endMarker"></span>


</div><!--#content-->
</div><!--#container-->
</body>
</html>

我想跳转到id,sigil_toc_id_10所在的最后一页,其中包含mWebView.loadUrl(“javascript:document.getElementById(\”“+ anchorId +”\“)。scrollIntoView()”)但是scrollIntoView方法不起作用。如何跳转到最后一页不使用setColumn方法但使用id,sigil_toc_id_10?

0 个答案:

没有答案