View instance: Demo Demo package download
Xhtml
Copy Code code as follows:
<a href= "#" id= "switch" > Switch layout </a>
<div id= "Demo" class= "Showlist" >
<div class= "List" >
<p> Article Summary </p>
</div>
...
</div>
In the XHTML architecture, multiple. List is placed in the #demo to display the title and summary of the article. Use the following CSS to control the appearance.
Css
Copy Code code as follows:
#demo {width:680px; margin:20px auto; padding:4px; background: #f7f7f7;
border:1px Solid #d3d3d3}
. list{margin:6px}
. list h3{height:26px; line-height:26px font-size:14px}
. List p{line-height:20px}
. showblock. list{float:left; width:325px; height:100px}
We want to set the outermost #demo style so that it has a uniform appearance, including background color and border style. Notice that we're going to set a style at the end. Showblock. list, control the. List style in #demo, make it float to the left, and set the height and width. showblock is actually setting the #demo style, and in the next jquery code, You'll get it. Of course, you can design CSS and XHTML on your own, just to demonstrate the simplicity of building a style and HTML structure.
Jquery
The principle of switching layouts is to use JavaScript to control the way the page is displayed and to refer to different Cssy styles when the user clicks on the switch. Take a look at the jquery code below.
Copy Code code as follows:
$ (function () {
$ ("#switch"). Toggle (function () {
$ ("#demo"). Fadeout ("Fast", function () {
$ (this). FadeIn ("Fast"). AddClass ("Showblock");
});
},function () {
$ ("#demo"). Fadeout ("Fast", function () {
$ (this). FadeIn ("Fast"). Removeclass ("Showblock");
});
});
});
We use the toggle event, which is used to alternately execute the event, using fadeout to make the switch have a transition effect, it is not difficult to see that through AddClass () and Removeclass () call different styles to achieve different layout effects.
Question: After paging, how do I switch the layout and go to the next page and the layout of the previous page?
Thinking: You can use cookies to record the layout of the user's choice, and then go to the next page to read the cookie value, distribution layout, and so on. About the use of cookies, you can refer to this site article: using jquery to operate cookies