JS and CSS Implementation footnote (Footnote) effect

Source: Internet
Author: User
Tags implement

Footnotes (Footnote) are an excellent way to provide more information to users and an effective complement to the subject information, which is common in a variety of printed books. However, since footnotes have these benefits, of course we have to take advantage of them in Web pages, this article gives you a way to implement footnote effects with JavaScript and CSS.

Javascript:

<script type= "Text/javascript" >
Description: Implement footnote (Footnote) effects with Javascript and CSS
Author: codebit.cn (http://www.CodeBit.cn)
var footnotes = function () {};
Footnotes.prototype = {
Footnoteclassname: "Footnote",//footnote className
Footnotetagname: "Span",//footnote label name
Footnotebacklink: "[Back]",//Return link
Format:function (ContentID, Footnoteid)
{
if (!document.getelementbyid) return false;
var content = document.getElementById (ContentID);
var footnote = document.getElementById (Footnoteid);
var spans = content.getelementsbytagname (this.footnotetagname);
var notearr = [];
var note = 0;
var elcontent;
var len = spans.length;
for (i=0; i<len; i++)
{
Note + +;
if (Spans[i].classname = = this.footnoteclassname)
{
Get footer Contents
Elcontent = spans[i].innerhtml;
Notearr.push (elcontent);
Create a link to a footnote
var Newele = document.createelement ("a");
Newele.href = ' #ftn_ ' + Footnoteid + ' _ ' + Note;
Newele.title = "Show footnote";
newele.id = ' Ftnlink_ ' +footnoteid+ ' _ ' + Note;
newele.innerhtml = Note;
Empty the original content
while (Spans[i].childnodes.length)
{
Spans[i].removechild (Spans[i].firstchild);
}
Spans[i].appendchild (Newele);
}
}
Create a comment list
var ul = this.__buildnotelist (Notearr, Footnoteid);
Footnote.appendchild (UL);
},
__buildnotelist:function (notes, Noteid)
{
if (!notes | | notes.length < 1) return;
var ul = document.createelement (' ul ');
Ul.classname = This.footnoteclassname;
var Li;
var len = notes.length + 1;
for (I=1; i<len; i++)
{
Li = document.createelement (' li ');
Li.id = "Ftn_" +noteid+ "_" +i;
li.innerhtml = Notes[i-1];
To create a "back" link
var link = document.createelement ("a");
Link.href = "#ftnlink_" + Noteid + "_" + I;
link.innerhtml = This.footnotebacklink;
Li.appendchild (link);
Ul.appendchild (LI);
}
return ul;
}
};
</script>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.