Magnifier Effect---enlarge.js

Source: Internet
Author: User

HTML page:

Note: The size of the matte layer depends on = = = "Layerwidth/layerheight = Largewidth/largeheight

Enlarge.js page

/*
Jquery.enlarge.js v1.1
by Abelyao, usky.org
*/

(Function ($)
{
var defaults =
{
Shadecolor: "#FFD24D",
Shadeborder: "#FF8000",
shadeopacity:0.5,
Cursor: "Move",

layerwidth:400,
LAYERHEIGHT:300,
Layerborder: "#DDD",
Fade:true,

largewidth:1280,
largeheight:960
}

var enlarge = function (option)
{
option = $.extend ({}, defaults, option);

$ (this). each (function ()
{
var = $ (this). CSS ("position", "relative");
var img = Self.children (). First ();

var ratio =
{
X:img.width ()/Option.largewidth,
Y:img.height ()/Option.largeheight
}

var size =
{
Shade
{
Width:option.layerwidth * ratio.x,
Height:option.layerheight * RATIO.Y
}
}

var shade = $ ("<div>"). CSS (
{
"Position": "Absolute",
"Left": "0px",
"Top": "0px",
"Background-color": Option.shadecolor,
"Border": "1px solid" + Option.shadeborder,
"width": size.shade.width,
"Height": size.shade.height,
"Opacity": option.shadeopacity,
"Cursor": option.cursor
});
Shade.hide (). AppendTo (self);

var large = $ ("{
"Position": "Absolute",
"Display": "Block",
"width": option.largewidth,
"Height": option.largeheight
});
var layer = $ ("<div>"). CSS (
{
"Position": "Absolute",
"Left": self.width () + 5,
"Top": 0,
"Background-color": "#111",
"Overflow": "Hidden",
"width": option.layerwidth,
"Height": option.layerheight,
"Border": "1px solid" + Option.layerborder
});
Large.attr ("src", self.attr ("href"));
Large.appendto (layer);
Layer.hide (). AppendTo (self);

var half =
{
X:SIZE.SHADE.WIDTH/2,
Y:size.shade.height/2
}

var area =
{
Width:self.innerWidth ()-Shade.outerwidth (),
Height:self.innerHeight ()-Shade.outerheight ()
}

var offset = Self.offset ();

var show = function ()
{
offset = Self.offset ();
Shade.show ();
if (Option.fade) Layer.stop (). FadeIn (300);
else Layer.show ();
}

var hide = function ()
{
Shade.hide ();
Layer.hide ();
}

Self.mousemove (function (e)
{
var x = E.pagex-offset.left;
var y = e.pagey-offset.top;

if (x < 0 | | x > Self.innerwidth ()) return hide ();
if (Y < 0 | | y > self.innerheight ()) return hide ();

x = x-half.x;
y = y-half.y;

if (x < 0) x = 0;
if (Y < 0) y = 0;
if (x > Area.width) x = area.width;
if (y > area.height) y = area.height;

SHADE.CSS (
{
Left:x,
Top:y
});

LARGE.CSS (
{
Left: (0-x/ratio.x),
Top: (0-y/RATIO.Y)
});
})
. MouseEnter (show)
. MouseLeave (hide);
});
}

$.fn.extend (
{
Enlarge:enlarge
});
}) (JQuery)

Reference URL: https://github.com/abelyao/enlarge.js

Magnifier Effect---enlarge.js

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.