I have a JavaScript like this
$(document).on('click', '.transparent-btns_nav', function(event) {
var images = $('.rslides ').find('img');
setTimeout(function() {
images.each(function() { // jQuery each loops over a jQuery obj
var h = $(this).outerHeight(true); // $(this) is the current image
var w = $(this).outerWidth(true);
// alert('source:'+$(this).attr('src'));
// alert('alto: '+h);
if (h < 290) {
$(this).addClass('small');
var m = 290 - h;
m = m / 2;
// alert('less height');
$('.small').attr('style', 'margin-top:' + m);
// $('.small').css('margin-top', +m + "px");
// $('.small').css('margin-bottom', +m + "px");
}
if (h > 290) {
$(this).addClass('big');
var m = h - 290;
m = m / 2;
// alert('less height');
$('.small').attr('style', 'margin-top:' - m);
}
});
}, 1000);
});
And Media Query something like this
@media only screen
and (min-device-width: 420px)
and (orientation: landscape) {
#bg {
}
#bg img {
margin - top: 0px;
}
.class {
margin-top: 0px;
margin-bottom: 0px;
}
.big {
margin-top: 0px;
margin-bottom: 0px;
}
}
What I want to do is add attributes to class big
and small
using the JavaScript and remove the attribute using the MediaQuery
when the mode is Landscape . But I am not able to do it can some one please help me out in this
More Explanation
I am trying to add padding to the image which are bigger or smaller than the div . Like if its height is smaller then equal padding on the top and the bottom .If the height of the image is tooo big then I am trying to add -ve padding at the top and center the image . All these are done dynamically in portrait mode . If the phone is turned into landscape all the padding should be removed