I'm trying to do an animation which runs by clicking on aside tag. after this, I want to run the asideAnime function again when resizing screen (window).
this my JS code :
var image_url = $('aside').css('background-image'),image;
// Removing url() or in case of Chrome url("")
image_url = image_url.match(/^url\("?(.+?)"?\)$/);
if (image_url[1]) {
image_url = image_url[1];
image = new Image();
$(image).load(function () {
var a = image.width;
var b = image.height;
var c = $(window).width();
var d = $(window).height();
var e = ((d-b)/b); //height inscrease amount ratio
var f = a+(e*a); //changing width based on height change
$('aside').click(function(){
asideAnime(a,b,c,d,e,f);
$(this).addClass('done');
});
});
image.src = image_url;
}
var asideAnime = function(a,b,c,d,e,f) {
var g = $('aside').width();
var h = (e*a); //the amount change in width
var condition = h > -100;
$('aside').animate({
width: f,
maxWidth: c
});
if(condition) {
$('.main').animate({
right: -f,
left: f,
marginLeft: "0"
});
} else {
$('.main').animate({
right: "0",
left: f,
marginLeft: "0"
});
};
}
I tried to do this by using if statement before the resize function, but it didn't work..
if ($('aside').hasClass('done')) {
$(window).resize(function(){
asideAnime(a,b,c,d,e,f);
});
}
anybody has any idea ? thanks
To explain more:
there is aside tag with 30% width and a background image with background-size:cover .
by clicking aside, the aside opens and shows the full image. all this lines of codes are because I'm trying to open aside according to the change in bg made by background-size:cover while keeping the ratio.
screenin javascript, and resizing it would be difficult as it's the screen, so you should be more specific and always usewindow