I was wondering: I have a background image on a site I'm working on that needs to be very exactly positioned. Currently, its positioning is:
body {
...
width: 100%
background-position-x: center;
background-position-y: -10px;
}
This works pretty well -- for the most part the image stays centered in the x axis when a user resizes a window.
However, if the user resizes the window to an odd pixel width (ie body becomes 1001px not 1000px) then the background image seems to be positioned off by a bit (maybe 1 pixel?).
How can I fix this? Do I have to limit the element width to even numbers/how do I do this? Is there maybe a jQuery solution to this?
EDIT: A site named Simplegeo https://simplegeo.com/ manages to do this perfectly. Notice the tiled background: it's made with a repeated png file, and it's always perfectly positioned against the elements on the page. This shows it's possible.. but does anyone know how they did it?
The way I see it, you got two options:
1) Resize the users window till to the closest even number (when a resize happens), something like this http://jsfiddle.net/hATKW/
2) Use a fixed width along with media queries to account for multiple sized windows, read on Media Queries here: http://css-tricks.com/6731-css-media-queries/
Thanks,
Leo
This website uses a background image which is 20x20 pix (even number). You may use
body {
min-width:400px;
}
At this width 1px off will be hardly be detectable and if the user re-sizes to larger window, the difference will be hardly noticeable.
I am not exactly sure about your question though. You are talking about element in the question, not the background. Would be helpful if you provide your site link.
Related
I'm using openseadragon with the excellent svg overlay plugin.
On Chrome, the app behaves as expected: users can tap to zoom in until a table rendered in SVG is fully visible, the note on the table is legible.
Here's the link to the demo. Zoom out to see the SVG version of the table appear, overlaying the fuzzy raster version of the background.
On Safari on iOS or OSX when zooming past a seemingly arbitrary threshold the table and everything on it start to disappear. The point of disappearance seems to depend on other factors I don't understand, hence this question for insight. For example, a orange circle drawn with two.js will disappear when the scale transform is precisely 51201 (at 51200 the circle is there). For the more complex table SVG, elements on the table will disappear at different scale levels, between ~23000 to 50000. Sometimes they'll disappear and then reappear upon a slight zoom in. Sometimes they'll disappear on zoom and then reappear as I pan around, the objects nearing the edge of the viewport.
IE 11 has a very similar issue.
Has anyone dealt with this before or solved it?
That's a really slick project!
In my experience, that kind of problem with SVG disappearing has to do with extreme amounts of zoom. The good news is you should be able to work around it by changing your viewport coordinates. By default the width of the image is a viewport value of 1, but you can set your image to be width 10,000 or some such, which will look exactly the same on the screen, but it means that the SVG thinks it's zoomed out a lot at first, so when you zoom in you can go a lot further.
If you're using two.js, another possible fix would be to switch over to canvas rendering and use https://github.com/altert/OpenSeadragonCanvasOverlay.
Btw, I'd love to share your project when it's done... please file a ticket at https://github.com/openseadragon/site-build/issues when you're ready and we can add it to http://openseadragon.github.io/examples/in-the-wild/.
Here's a fun one: in iOS8, repeating an image was as simple as using 0px edge insets and setting the center to "Tiles." On iOS9 however, the images do not tile. Instead, the blank space copies the edge pixel forever - and not from the sides I would expect:
Perhaps I'm doing this wrong? Is there a better way to achieve a tiled background?
I found a workaround. For some reason, if you only slice the image horizontally, the image tiles correctly. I DO NOT recommend this to anyone here looking for a quick fix, as I do not know how this affects previous versions of iOS. Or why it even works in the first place. If anyone can provide a better answer, I'll accept it instead.
displaycontent = display.newImageRect (rawdata[currentpath][3], screenW*1.1, ((screenW*1.1/1654)*rawdata[currentpath][6]))
displaycontent.anchorY = 0
displaycontent.y = screenH*0.78
My program loads an image from a database to be displayed on the mobile phone's screen, everything works correctly apart from being able to position it with the y coordinates.
The only thing that changes its position is the anchor point 0 puts the top of the image in the centre of the screen, and values from 0.1 - 1 all position it higher. Changing the y position via object.y has zero effect regardless of what I set it as.
(the size settings probably look a bit weird in the first line, but this is because the images are different sizes and need to show the correct proportions on different screen types).
Btw I am using a tabbar widget as the UI (in case that is relevant)
Any help would be appreciated.
Edit: I am aware that displaycontent is bad name for a variable because of its similarity to things like display.contentCenterY for example, this will be changed to prevent any confusion when I look over the code in future.
I went through my code and tried disabling sections to find the culprit and a content mask was preventing me from setting the position of the loaded images within it.
I will look over my masking code and fix it (should be straight forward now I know where the problem started).
If anyone else has a similar problem (where an image or object wont position itself on given coordinates) check your content mask as that may be the issue!
I am making an interactive storybook project given these specifications:
My book has 13 pages, where 1 page = 1 swf loaded externally into the book swf. As you can see, the page swf must be centered in between the 2 buttons that are both 100x450 each. Whenever I try to load the swf, usually it's cut off at some point.
In short, how do I center my externally swf when loaded?
Make the completeHandler Function like given bellow
function completeHandler(event:Event):void{
this.container.addChild(event.target.content);
this.container.x = this.stage.stageWidth/2 - event.target.width /2;
this.container.y = this.stage.stageHeight/2 - event.target.height /2;
}
U can change this.stage.stageWidth with the center container width and apply same for width also
The advice gyandas gives is good. However, from the way you've worded your question I'm guessing you're already doing something along the lines of what he suggests. If so, you could try adding a filled shape of 520x450 as the background of each of your pages. You can set the alpha to 0 or match the background color of the book itself, but the important thing is to have some actual content of the required dimensions rather than relying on the supposed width of the SWF when centering it in another movie.
I'm not in a position to test this right now, but I seem to recall that the dimensions of a loaded SWF are calculated according to the bounding box created around actual content, and that I have resorted to doing this as a result.
I have used the coin slider.But the coin slider is restricted by the width.I need to run my application in various screen size like 1280*768,800*600.is there any image slider in jquery without restrict width of image?Please help me.
Thanks in advance.
Most image sliders are designed for being placed within a container of a certain width, so that they fit within a specific slot in a layout. Given that the size of the screen/window(you don't specify) is irrelevant to that, it seems like what you're looking for is a gallery that adapts to the size of the entire window, rather than fit within a specific size.
You should probably widen your search to JS galleries in general, which might have that option or even function that way in the first place. As initial suggestions, have a look at the full-screen example for Galleria, or maybe the Supersized plugin