jquery Implementation Switch page layout use introduction _jquery

Source: Internet
Author: User
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

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.