TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Marginotes, quick and elegant side notes for your paragraphs

111 pointsby Statelyabout 9 years ago

10 comments

lolcabout 9 years ago
Looks nice!<p>I was a little surprised at the last line in your code:<p>window.jQuery.prototype.marginotes = window.$.prototype.marginotes = marginotes<p>Last I checked (one minute ago) jQuery and $ refer to the same object. jQuery === $ unless somebody is using $ to refer to something else in which case thanks you just clobbered $&#x27;s prototype. You should follow the jQuery conventions <a href="https:&#x2F;&#x2F;learn.jquery.com&#x2F;plugins&#x2F;basic-plugin-creation&#x2F;" rel="nofollow">https:&#x2F;&#x2F;learn.jquery.com&#x2F;plugins&#x2F;basic-plugin-creation&#x2F;</a>
Chris_Newtonabout 9 years ago
Notes on web pages are tricky because there are so many edge cases, and they tend to expose the limitations of our current HTML+CSS model.<p>For example, we can achieve an effect similar to the one shown here using just CSS (no JS) if we’re able to use position:relative on the containing paragraph without breaking anything else in the styling:<p>HTML:<p><pre><code> &lt;p class=&quot;note-container&quot;&gt;This is some text with a &lt;span class=&quot;note&quot; desc=&quot;Style me!&quot;&gt;marginal note&lt;&#x2F;span&gt;. Lorem ipsum dolor sit amet...&lt;&#x2F;p&gt; </code></pre> CSS:<p><pre><code> .note-container { position: relative; width: 400px; } .note { text-decoration: underline; } .note:hover::after { content: attr(desc); position: absolute; top: 0; left: 440px; width: 150px; height: 100%; border-left: 1px solid black; padding-left: 9px; } </code></pre> I put a quick demo of this one here:<p><a href="https:&#x2F;&#x2F;jsfiddle.net&#x2F;2ejk2who&#x2F;" rel="nofollow">https:&#x2F;&#x2F;jsfiddle.net&#x2F;2ejk2who&#x2F;</a><p>However, what happens if we need to work with touch-only devices, where hover effects aren’t available? Two options would be to show the notes all the time, or to embed a hidden checkbox and make the anchor text its label. In the latter case, tapping on the text could then toggle whether the marginal note appears if we used something based on :checked instead of :hover.<p>But now what if more than one note is set to visible at once? We can’t combine the position:absolute technique to get neat alignment at the top of the paragraph with using floats so multiple notes automatically fall under one another. I don’t have a good pure-CSS answer for this one.<p>In any case, on a smaller screen we might not want to show marginal notes alongside the main text anyway. It would be helpful if there were a way to have the notes drop underneath the paragraph and stack up, but again, we can’t combine the kind of absolute positioning that would place a note there with something that extends the paragraph’s box so later content moves down after any visible notes.<p>Perhaps one day we’ll have more flexible options for generated content and CSS positioning that will let us do these things, but for now the only ways I know to achieve some of these effects still rely on JS.
mshenfieldabout 9 years ago
I made a little experiment, and converted this to a vanilla Javascript library. Relevant to some of the questions below about whether this should use jQuery or not.<p>Edit: There were two gotchas beyond browser compatibility. jQuery provides a consistent interface to set numeric style values - in vanilla Javascript you have to remember to turn these numbers into strings suffixed with &quot;px&quot;. And I hacked together the code that stops fadein and fadeout from stepping on each other.<p>Changes: <a href="https:&#x2F;&#x2F;github.com&#x2F;fdansv&#x2F;marginotes&#x2F;pull&#x2F;2" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;fdansv&#x2F;marginotes&#x2F;pull&#x2F;2</a> Working Example: <a href="http:&#x2F;&#x2F;mshenfield.github.io&#x2F;fdansv.github.io&#x2F;" rel="nofollow">http:&#x2F;&#x2F;mshenfield.github.io&#x2F;fdansv.github.io&#x2F;</a>
评论 #11254007 未加载
kozakabout 9 years ago
Very nice. It would be even better if it had some CSS media query-based fallbacks for the case when the page is being printed. And yes, jQuery should not be a requirement.
joeclark77about 9 years ago
This is excellent. I&#x27;ve been thinking about rolling my own blog software since Medium took away their marginal note feature (IIRC, you can now make notes but they&#x27;re for yourself only, readers can&#x27;t see them). Since reading Ed Tufte&#x27;s books, I&#x27;m convinced that margin notes are infinitely better than footnotes or (egad) endnotes for sharing little &quot;extras&quot; with your readers.
tauchunfallabout 9 years ago
Mouse-over actions are nice on desktop. But what happens if I use a touch device?
评论 #11253414 未加载
DenisAyumuabout 9 years ago
Last time I checked you couldn&#x27;t add HTML properties that don&#x27;t exist. It&#x27;s not valid HTML code. The exception are &quot;data-*&quot; properties. So the HTML markup should be &lt;span data-desc=&quot;whatever&quot;&gt;whatever&lt;&#x2F;span&gt;.
gkyaabout 9 years ago
What happens if I have JavaScript disabled (and I do have)?
评论 #11252974 未加载
评论 #11252739 未加载
anacletoabout 9 years ago
Pretty. Thanks.
gbergerabout 9 years ago
<a href="http:&#x2F;&#x2F;youmightnotneedjquery.com&#x2F;" rel="nofollow">http:&#x2F;&#x2F;youmightnotneedjquery.com&#x2F;</a>
评论 #11252527 未加载
评论 #11252504 未加载
评论 #11253455 未加载