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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745316440a4622239.html
评论列表(0条)