About the answer:
(1) When Charles Dickens clicked, apply the selected style to it.
$ (document). Ready (function () {
$ (' #header '). On (' click ', function () {
$ ('. Author '). addclass (' selected ')
});
})
(2) Toggle the visibility of the chapter text when you double-click the chapter title (
$ (document). Ready (function () {
$ (' #chapter-preface '). On (' DblClick ', function () {
$ ('. Chapter-title '). Toggleclass (' hidden ');
})
})
//(3) when the user presses the RIGHT ARROW key, switches to the next body class; The key code for the right ARROW key is 39.
//var setbodyclass=function (className) {
//$ ("body"). Removeclass (). addclass (className);
$ (". Switcher button"). Removeclass ("selected");
//$ ("#switcher-" +classname). AddClass ("selected");
//}
////When the page is initially selected by default
//$ ("#switcher-default"). AddClass ("selected");
$ (document). KeyUp (function (event) {
//var num=$ (". Switcher button"). Filter (". Selected"). Index ()-1;
alert (num);
//if (event.which==39) num= (num+1)%3;
//else if (event.which==37) num= (num-1)%3;
//else return false;
//Var btnclassname=$ (". Switcher button"). EQ (num). attr ("id"). Split ("-") [1];
//Setbodyclass (Btnclassname);
//})
The second method of
$ (function () {
var setbodyclass=function (className) {
$ ("Body"). Removeclass (). addclass (ClassName);
$ (". Switcher button"). Removeclass ("selected");
$ ("#switcher-" +classname). AddClass ("selected");
}
$ ("#switcher-default"). AddClass ("selected");//The page is initially selected by default
var bodyclass=["Default", "narrow", "large"];
var count=0;//set a counter
$ (document). KeyUp (function (event) {
if (Event.keycode = = 39) {
Setbodyclass (bodyclass[(count+1)%3]);//If set to count%3 the page will not react when the right button is pressed for the first time (because the default is Setbodyclass[0])
count++;
}
})
})
//(4) Challenge: Use the Console.log () function to record the coordinate position of the mouse moving in a paragraph. (Note: Console.log () can be used in Firefox's firebug extension, Safari's Web Inspector, or developer tools in Chrome, ie.
//Get mouse coordinate function
$ (document). Ready (function () {
//get mouse coordinate function
$ (document). MouseOver (function (e) {
var x = E.pagex;
var y = e.pagey;
Console.log (' x-coordinate ' +x+ ', ' + ' y-coordinate ' +y);
})
})
(5) Challenge: Use. MouseDown () and. MouseUp () to track mouse events in the page. If the mouse button is released where it is pressed, the hidden class is added for all paragraphs. If it is released under the place where it was pressed, delete all paragraphs of the hidden class.
$ (document). Ready (function () {
varposxr=0,posy=0;
$ (document). MouseDown (function (event) {
Posx=event.clientx;
Posy=event.clienty;
})
$ (document). MouseUp (function (event) {
Posx1=event.clientx;
Posy1=event.clienty;
if (POSY1==POSY&&POSX==POSX1) {
$ (' P '). addclass (' hidden ')
}
else if (posy1>posy) {
$ (' P '). Removeclass (' hidden ')
}
})
})
Book matching source code HTML:
<! DOCTYPE html>
<meta charset= "Utf-8" >
<title>a Christmas carol</title>
<link rel= "stylesheet" href= "Css/03.css" type= "Text/css"/>
<script src= "Jquery.js" ></script>
<script src= "Js/03.js" ></script>
<body>
<div id= "Container" >
<div id= "switcher" class= "Switcher" >
<button id= "Switcher-default" >
Default
</button>
<button id= "Switcher-narrow" >
Narrow Column
</button>
<button id= "Switcher-large" >
Large Print
</button>
</div>
<div id= "Header" >
<H2 class= "subtitle" >in Prose, Being a Ghost story of christmas<div class= "Author" >by Charles dickens</div>
</div>
<div class= "chapter" id= "Chapter-preface" >
<p>i has endeavoured in this ghostly little book, to raise the Ghost of a idea, which shall isn't put my readers out Of humour with themselves, with all other, with the season, or with me. May it haunt their houses pleasantly, and no one wish to lay it.</p>
<p>their Faithful Friend and servant,</p>
<p>c. d.</p>
<p>december, 1843.</p>
</div>
<div class= "chapter" id= "Chapter-1" >
<p>marley was dead:to begin with. There is no doubt whatever on that. The register of his burial is signed by the clergyman, the clerk, The Undertaker, and the Chief mourner. Scrooge signed It:and Scrooge's name was good the upon ' change, the for anything he chose to put the he hand to. Old Marley is as dead as a door-nail.</p>
<p>mind! I don ' t mean to say that I know, the of my own knowledge, what there was particularly dead about a door-nail. I might has been inclined, myself, to regard a coffin-nail as the deadest piece of ironmongery in the trade. But the wisdom of our ancestors are in the simile; And my unhallowed hands shall not disturb it, or the country ' s did for. You'll therefore permit me to repeat, emphatically, that's Marley was as dead as a door-nail.</p>
<p>scrooge knew he was dead? Of course he did. How could it is otherwise? Scrooge and he were partners for I don ' t know how many years. Scrooge was he sole executor, his sole administrator, his sole assign, he sole residuary Legatee, his sole friend, and S Ole Mourner. And even Scrooge was wasn't so dreadfully cut up by the sad event, but that he is an excellent man's business on the very D Ay of the funeral, and solemnised it with an undoubted bargain.</p>
<p>the mention of Marley ' s funeral brings me back to the point I-started from. There is no doubt this Marley was dead. This must is distinctly understood, or nothing wonderful can come of the stories I am going to relate. If We were not perfectly convinced that Hamlet ' s Father died the play before, began there is nothing more would In he taking a stroll at night, in an easterly wind, upon he own ramparts, than there would is in any other middle-aged Gentleman rashly turning out after dark in a breezy Spot—say Saint Paul's churchyard for instance— Literally to Astonish he son ' s weak mind.</p>
<p>scrooge never painted out old Marley ' s name. There it stood, years afterwards, above the warehouse Door:scrooge and Marley. The firm was known as Scrooge and Marley. Sometimes people new to the business called Scrooge Scrooge, and sometimes Marley, but he answered to both names. It is all the same to him.</p>
<p>oh! But he is a tight-fisted hand at the Grind-stone, scrooge! A squeezing, wrenching, grasping, scraping, clutching, covetous, old sinner! Hard and sharp as flint, from which no steel had ever struck off generous fire; Secret, and self-contained, and solitary as an oyster. The cold within him froze his old features, nipped he pointed nose, shrivelled his cheek, stiffened his gait; Made his eyes red, his thin lips blue; And spoke out shrewdly in his grating voice. A Frosty Rime is on his head, and the his eyebrows, and his wiry chin. He carried his own the low temperature always on with him; He iced his office in the Dog-days; and didn ' t thaw it one degree at christmas.</p>
<p>external heat and cold had little influence on Scrooge. No warmth could warm, no wintry weather chill him. No wind this blew was bitterer than he, no falling snow is more intent upon it purpose, no pelting rain less open to ENT Reaty. Foul weather didn ' t know where to has him. The heaviest rain, and snow, and hail, and sleet, could boast of the advantage over him on only one respect. They often "came down" handsomely, and Scrooge never did.</p>
<p>nobody ever stopped him in the street to say, with Gladsome looks, "My dear Scrooge, How is it?" When would you come to see me? " No beggars implored him to bestow a trifle, no children asked him what it is O ' clock, no man or woman ever once in all hi s life inquired the same-such and such a place, of Scrooge. Even the blind men's dogs appeared to know him; And when they saw him coming on, would tug their owners to doorways and up courts; And then would wag their tails as though they said, "No eye @ All are better than an evil eye, dark master!" </p>
<p>but What did Scrooge care! It was the very thing he liked. To edge his-along the crowded paths of life, warning all human sympathy-keep its distance, is what the knowing one s call "nuts" to scrooge.</p>
</div>
</div>
</body>
CSS for book matching:
/***************************************
Default Styles
************************************** */
HTML, Body {
margin:0;
padding:0;
}
Body {
font:62.5% Verdana, Helvetica, Arial, Sans-serif;
Color: #000;
Background: #fff;
}
#container {
Font-size:1.2em;
margin:10px 2em;
}
H1 {
Font-size:2.5em;
margin-bottom:0;
}
H2 {
Font-size:1.3em;
Margin-bottom:. 5em;
}
h3 {
Font-size:1.1em;
margin-bottom:0;
}
Code {
Font-size:1.2em;
}
A
Color: #06581f;
}
/***************************************
Chapter Styles
************************************** */
. poem {
Margin:0 5em;
}
. Chapter {
Margin:1em;
}
. switcher {
Float:right;
Background-color: #ddd;
border:1px solid #000;
margin:10px;
padding:10px;
Font-size:. 9em;
}
. switcher H3 {
margin:. 5em 0;
}
#header {
Clear:both;
}
Body.large. Chapter {
Font-size:1.5em;
}
Body.narrow. Chapter {
width:250px;
}
. Selected {
Font-weight:bold;
}
. Hidden {
Display:none;
}
. hover {
Cursor:pointer;
Background-color: #afa;
}
Some are borrowed from others ' blogs. If there is an impact, the invasion of the deletion.
The basic jquery Tutorial (Fourth Edition), chapter 3rd, exercises: