Skip to content

Commit 269801a

Browse files
committed
add scale toggle and size to functional demos + move origin calculations to size
1 parent 1c97a16 commit 269801a

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
lines changed

demos/functional/templates/ui.effects.general.html

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
{
6161
title: 'Scale',
62-
desc: 'Change the size of an element.',
62+
desc: 'Scales and element by a percentage.',
6363
html: '<button id="doScale">Scale</button> \n' +
6464
'<button onclick="$(\'#scale\').css({width: 144, height: 108});">Reset</button><br/>\n' +
6565
'<div style="height: 108px;"><img id="scale" src="templates/images/P1010063.JPG"/></div>',
@@ -75,6 +75,22 @@
7575
{ desc: 'Scale from bottom-right', source: '$("#doScale").click(function() { $("#scale").effect("scale", {origin: ["bottom", "right"], percent: 50}, 2000); });' }
7676
]
7777
},
78+
79+
{
80+
title: 'Size',
81+
desc: 'Change the size of an element.',
82+
html: '<button id="doSize">Size</button> \n' +
83+
'<button onclick="$(\'#size\').css({width: 144, height: 108});">Reset</button><br/>\n' +
84+
'<div style="height: 108px;"><img id="size" src="templates/images/P1010063.JPG"/></div>',
85+
destroy: '$("#doSize").unbind();',
86+
87+
options: [
88+
{ desc: 'Size to 75x200', source: '$("#doSize").click(function() { $("#size").effect("size", {to: {width:75, height:200}}, 2000); });' },
89+
{ desc: 'Size to 200x75', source: '$("#doSize").click(function() { $("#size").effect("size", {to: {width:200, height:75}}, 2000); });' },
90+
{ desc: 'Size (125x210) from middle-center', source: '$("#doSize").click(function() { $("#size").effect("size", {to: {width:125, height:210}, origin: ["middle", "center"]}, 2000); });' },
91+
{ desc: 'Size (210x125) from bottom-right', source: '$("#doSize").click(function() { $("#size").effect("size", {to: {width:210, height:125}, origin: ["bottom", "right"]}, 2000); });' }
92+
]
93+
},
7894

7995
{
8096
title: 'Shake',

demos/functional/templates/ui.effects.showhide.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,21 @@
103103
{ desc: 'Puff to 200%', source: '$("#doPuff").click(function() { $(".pufffx").toggle("puff", {percent: 200}, 2000); });' }
104104
]
105105
},
106+
107+
{
108+
title: 'Scale',
109+
desc: 'Grow/Shrink an element.',
110+
html: '<button id="doScale">Toggle</button><br/>\n' +
111+
'<ul><li style="float: left; width: 144px; height: 108px;"><img class="scalefx" style="width: 144px; height: 108px;" src="templates/images/P1010058.JPG"/></li>\n' +
112+
'<li style="float: left; width: 144px; height: 108px; margin-left: 20px;"><div class="scalefx" style="width: 144px; height: 108px; background-color: #F2F2F2;">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ...</div></li></ul>\n' +
113+
'<div style="clear: both;"></div>',
114+
destroy: '$("#doPuff").unbind();',
115+
116+
options: [
117+
{ desc: 'Scale defaults', source: '$("#doScale").click(function() { $(".scalefx").toggle("scale", {}, 2000); });' }
118+
]
119+
},
120+
106121

107122
{
108123
title: 'Slide',

ui/effects.scale.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ $.effects.scale = function(o) {
5656
var direction = o.options.direction || 'both'; // Set default axis
5757
var origin = o.options.origin; // The origin of the scaling
5858
if (mode != 'effect') { // Set default origin and restore for show/hide
59-
origin = origin || ['middle','center'];
59+
options.origin = origin || ['middle','center'];
6060
options.restore = true;
6161
}
6262
var original = {height: el.height(), width: el.width()}; // Save original
@@ -68,13 +68,7 @@ $.effects.scale = function(o) {
6868
x: direction != 'vertical' ? (percent / 100) : 1
6969
};
7070
el.to = {height: original.height * factor.y, width: original.width * factor.x}; // Set to state
71-
if (origin) { // Calculate baseline shifts
72-
var baseline = $.effects.getBaseline(origin, original);
73-
el.from.top = (original.height - el.from.height) * baseline.y;
74-
el.from.left = (original.width - el.from.width) * baseline.x;
75-
el.to.top = (original.height - el.to.height) * baseline.y;
76-
el.to.left = (original.width - el.to.width) * baseline.x;
77-
};
71+
7872
if (o.options.fade) { // Fade option to support puff
7973
if (mode == 'show') {el.from.opacity = 0; el.to.opacity = 1;};
8074
if (mode == 'hide') {el.from.opacity = 1; el.to.opacity = 0;};
@@ -106,11 +100,18 @@ $.effects.size = function(o) {
106100
var mode = $.effects.setMode(el, o.options.mode || 'effect'); // Set Mode
107101
var restore = o.options.restore || false; // Default restore
108102
var scale = o.options.scale || 'both'; // Default scale mode
103+
var origin = o.options.origin; // The origin of the sizing
109104
var original = {height: el.height(), width: el.width()}; // Save original
110105
el.from = o.options.from || original; // Default from state
111106
el.to = o.options.to || original; // Default to state
112-
113107
// Adjust
108+
if (origin) { // Calculate baseline shifts
109+
var baseline = $.effects.getBaseline(origin, original);
110+
el.from.top = (original.height - el.from.height) * baseline.y;
111+
el.from.left = (original.width - el.from.width) * baseline.x;
112+
el.to.top = (original.height - el.to.height) * baseline.y;
113+
el.to.left = (original.width - el.to.width) * baseline.x;
114+
};
114115
var factor = { // Set scaling factor
115116
from: {y: el.from.height / original.height, x: el.from.width / original.width},
116117
to: {y: el.to.height / original.height, x: el.to.width / original.width}

0 commit comments

Comments
 (0)