The dock effect of the Apple desktop based on jquery (initial edition) _javascript tips

Source: Internet
Author: User

A new day to start, today to share is to use jquery to imitate the dock effect of Apple operating system desktop, called the primary version, because there are some bugs, the display effect is not stable. Due to the relationship between the time, these bugs have not been repaired, I hope the experts are not hesitate to enlighten, put forward a better opinion, I hope to make a better version to share.

This is a static effect chart, okay, looks like you want to be presentable.

The following is the code for the HTML page:

Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en"
"Http://www.w3.org/TR/html4/strict.dtd" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>JQueryProject1</title>
<meta name= "Author" content= "Frank_ren"/>
<link type= "Text/css" rel= "stylesheet" href= "Css/mycss.css"/>
<script type= "Text/javascript" src= "Js/jquery-1.4.2.js" ></script>
<script type= "Text/javascript" language= "JavaScript" src= "Js/myjsfile.js" ></script>
<!--date:2012-09-17-->
<body>
<div id= "topbody" align= "Center" >
<p id= "Topmenu" align= "Center" >









</p>
</div>
</body>

No CSS decorative pages that is a miserable, so use the appropriate CSS to decorate is essential
Copy Code code as follows:

#topBody {
height:300px;
}
#topMenu {
height:256px;
line-height:256px;
}
#topMenu img{
height:50px;
width:50px;
}

Just graduated for a few months, solve the equation are forgotten, so when the mouse moved when the icon amplification algorithm let me very headache ah, the algorithm here is just a personal idea, for reference only, I hope you master proposed a better algorithm. And here only consider the mouse in the horizontal position of the algorithm, has not joined the mouse to move the vertical algorithm.
Copy Code code as follows:

$ (function () {
$ ("#topBody"). MouseMove (function (e) {
var mousex = parseint (E.pagex);
$ ("#topMenu img"). each (function () {
var obj = $ (this);
var objwidth = obj.css ("width");
Get Picture Center Horizontal coordinate
var objx = parseint (Obj.offset (). left) + parseint (Objwidth.substr (0,objwidth.length-2))/2;
var x = Math.Abs (objx-mousex);
if (x<75 && x>-75) {
Obj.css ("width", (128-(78*x*x)/(75*75)) + "px");
Obj.css ("Height", (128-(78*x*x)/(75*75)) + "px");
}
});
});
});

To talk about the way jquery gets the mouse, when executing MouseMove (function (e) {}), the method's parameter E provides e.pagex get horizontal coordinates, E.pagey get vertical coordinates, and can also use var x = E.originalevent.x | | E.originalevent.layerx | | 0. Get the horizontal position of the mouse, also can use var y = E.originalevent.y | | E.originalevent.layery | | 0; Gets the vertical position of the mouse.

When the mouse moves slowly when the display effect is acceptable, but when the mouse quickly move the icon is magnified, but the corresponding bug also came out.

I implore you to pass through the master, the great God, put forward valuable changes and better algorithm, thank you for watching.

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.