JQuery achieves the effect of turning pages and Drawing links with the mouse, and turning pages with jquery

Source: Internet
Author: User

JQuery achieves the effect of turning pages and Drawing links with the mouse, and turning pages with jquery

On the Baidu map api homepage, we often see how jquery and js Code are implemented when the mouse goes through pages and links? Let's share the key code below. Let's take a look!

Var timer; $ ("li "). on ("mouseover", function () {clearTimeout (timer); timer = null; $ (this ). addClass ("active"); $ (this ). siblings (). removeClass ("active"); var $ index = $ (this ). index ();/* $ (". wrapper "). animate ({top:-$ index * 300}); */timer = setTimeout (function () {$ (". wrapper "). animate ({top:-$ index * 300}) ;}, 300)}); $ ('. dd '). find ($ (". cc ")). hover (function () {$ (this ). find (". c1 "). stop (). animate ({width: 0}, 100, function () {$ (this). Hide (). next (). show (). animate ({width: 300}, 100) ;}, function () {$ (this ). find (". c2 "). animate ({width: 0}, 100, function () {$ (this ). hide (). prev (). show (). animate ({width: 300}, 100) ;}); * {margin: 0; padding: 0; box-sizing: border-box} ul {list-style: none; border: 1px solid # ccc; border-radius: 5px; width: 900px; margin: 30px auto 10px ;}. clearfix {zoom: 1 ;}. clearfix: after {content :". "; display: block; width: 0; height: 0; visibility: Hidden; clear: both;} li {float: left; border-right: 1px solid # ccc; width: 20%; text-align: center; height: 30px; line-height: 30px; cursor: pointer;} li: last-child {border: none;} li. active {background-color: # 0099cc; color: # fff ;}. container ,. wrapper ,. con {height: 300px ;}. container {width: 900px; margin: 0 auto; position: relative; overflow: hidden ;}. wrapper {position: relative; top: 0 ;}. con {line-height: 300px; text-align: center; borde R: 1px solid # ccc ;}. dd {margin: 30px auto; width: pixel PX ;}. cc {float: left; width: 300px; height: 200px; overflow: hidden; margin: 20px ;}. c1 ,. c2 {width: 100%; height: 100%; margin: 0 auto; text-align: center; line-height: 200px; cursor: pointer; overflow: hidden }. c1 {background-color: # c01110 ;}. c2 {background-color: # 0099cc;} <! DOCTYPE html> 

Next we will introduce the anchor link.

1) Introduce jquery

2) Set class smooth for label

3)

$(".smooth").click(function(){         var href = $(this).attr("href");         var pos = $(href).offset().top;         $("html,body").animate({scrollTop:pos}, 1000);         return false;  });

The above section describes how jQuery achieves the effect of turning pages and Drawing links with the mouse. I hope it will be helpful to you. If you have any questions, please leave a message for me, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

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.