admin管理员组文章数量:1419640
On this site: /
Although the slider is full width / variable on browser window size, the Title of each slider item is always indented to line up with the content.
I've tried setting this up: /
$(window).resize(function() {
$('#item').css("padding-left",$(window).width()/2);
});
The function is working but the calculation pushes the item too far in on decreasing window size and too far out on increase.
The line in the working slider example is:
$('.layout-feature .box-section-image-gallery-controls-title, .layout-feature .box-section-image-gallery-title').css('paddingLeft', 60 + extraSpace/2);
where extraSpace
is the $(window).width()
Any help gratefully received - thanks in advance
On this site: http://houston.aiga/
Although the slider is full width / variable on browser window size, the Title of each slider item is always indented to line up with the content.
I've tried setting this up: http://jsfiddle/topiman/xS7vn/
$(window).resize(function() {
$('#item').css("padding-left",$(window).width()/2);
});
The function is working but the calculation pushes the item too far in on decreasing window size and too far out on increase.
The line in the working slider example is:
$('.layout-feature .box-section-image-gallery-controls-title, .layout-feature .box-section-image-gallery-title').css('paddingLeft', 60 + extraSpace/2);
where extraSpace
is the $(window).width()
Any help gratefully received - thanks in advance
Share Improve this question edited Apr 5, 2013 at 15:15 pb2q 59.7k19 gold badges150 silver badges152 bronze badges asked Apr 5, 2013 at 15:02 topimantopiman 5112 gold badges6 silver badges15 bronze badges 2- 1 shouldn't you take notice of the width of the body as well, not just the window width? – Luceos Commented Apr 5, 2013 at 15:11
- Updated fiddle: jsfiddle/topiman/xS7vn/5 Tried using: window, 'body', document - they all 'fire' correctly but I can't get the calculations to be the same as on the example site: houston.aiga – topiman Commented Apr 5, 2013 at 16:53
1 Answer
Reset to default 2It seems you forgot about the width after all: http://jsfiddle/topiman/xS7vn/5/
This is what I came up with. Stupid thing is the console.log kept giving back a +8 difference which I had to hardcode remove. Is this what you were looking for?
$(window).resize(function() {
var ItemWidth = $(".wrapper").width();
$('#item').width( ItemWidth );
var WindowWidth = $(window).width();
// cannot resize because window is smaller than the wrapper
if( ItemWidth > WindowWidth ) {
var PadWidth = 0;
} else {
var PadWidth = (WindowWidth - ItemWidth)/2 - 8;
}
console.log( ItemWidth + " - " + WindowWidth + " - " + PadWidth );
$('#item').css("margin-left",PadWidth + "px");
});
Update; also check http://jsfiddle/xS7vn/8/ for the latest update including resizing on page load.
本文标签: javascriptJQuery recalculate css on window resizeStack Overflow
版权声明:本文标题:javascript - JQuery recalculate css on window resize - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745316439a2653174.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论