/    Sign up×
Community /Pin to ProfileBookmark

Programmatically get first visible line

Hi,

In html document when user scrolls the page the first visible line is always changes, is there anyway I can get that line?

thanks,
webtekie

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@jamDec 04.2007 — hey, sorry but i dont understand what you mean, could you please attach some code so we can try help you out

Jamey
Copy linkTweet thisAlerts:
@webtekieauthorDec 04.2007 — There is no code yet. But what I want to achieve is some kind of automatic bookmarking mechanism where each time user scrolls the page, the topmost visible line is saved as a bookmark. May be there is something like this available already?
Copy linkTweet thisAlerts:
@jamDec 04.2007 — hmm, i still dont get what you mean by line?...

do you have the html?
Copy linkTweet thisAlerts:
@webtekieauthorDec 05.2007 — It can be any html document. Let's say you scroll this page that you are looking at, and the closest line to the top of the browser is your reply: "hmm, i still dont get what you mean by line?...", is there a way to capture that line somehow? Furthermore, every time you scroll, the top most line will be recalculated.
Copy linkTweet thisAlerts:
@jamDec 05.2007 — so by line you mean line of text?

i'm just trying to grasp the framework of the html...

something like:
[CODE]
<html>
...
<body>

<div>
This is the topmost line?
<div>


</body>
</html>
[/CODE]


?

if i had an example or the code behind what you're trying to do then i'd be able to help
Copy linkTweet thisAlerts:
@SmotsholleDec 05.2007 — Ehhh, you could probably do this by combining PHP with Javascript and I'm not talking about AJAX.

Each time the page scrolls you [U]get[/U] the yscroll of the document. You can generate a bookmark using that.

Example. Yscroll = 57 pixels, generated link => thispage.php?yscroll=57

In php you can include the following script on the bottom to [U]set [/U]the yscroll.

<script type="text/javascript">

<?php

if (!$_GET['yscroll']){

echo "document.yscroll = 0;";

} else {

echo "document.yscroll = ".$_
GET['yscroll'].";";

?>

</script>

I forgot the exact code for setting and getting the yscroll, and I'm short on time, but let me know if this solves your problem.
Copy linkTweet thisAlerts:
@webtekieauthorDec 05.2007 — Perfect! Thank you.
×

Success!

Help @webtekie spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...