2008年5月3日 星期六

jQuery memo 4


.css('property','value')
.css({property1: 'value1', 'property-2': 'value2'})



//parseFloat currentSize .css
var $speech = $('div.speech');
var currentSize = $speech.css('fontSize');
var num = parseFloat(currentSize, 10);
var unit = currentSize.slice(-2);

if (this.id == 'switcher-large') {
num *= 1.4;
} else if (this.id == 'switcher-small') {
num /= 1.4;
}
$speech.css('fontSize', num + unit);



Effect
hide show fadeIn fadeOut fadeTo slideDown slideUp animate

$('div.button').animate({left: 650, height: 38}, 'slow');

Positioning with CSS
position: relative absolute relative



Improving the custom animation
width() = .css('width')



Simultaneous versus Queued Effect
$('div.button')
.fadeTo('slow',0.5)
.animate({left: 650}, 'slow')
.fadeTo('slow',1.0)
.slideUp('slow');

//simultaneous, css這部份跟上面的effect是同步的
.fadeTo('slow',1.0);
.css('backgroundColor','#f00');

//如果要做到有順序有queue, 要靠callback function
.fadeTo('slow',1.0, function() {
$(this).css('backgroundColor','#f00');
});

沒有留言: