I'd like to get some ideas on how to implement this.
Here is the sketch:
Description: I have a scene (canvas on the sketch) and let's say 2 panels. Canvas lays in the DIV with position relative, panels are outside of this DIV and there are some elements over this DIV with position absolute. All these elements are draggable.
Every element is a div with inner canvas.
Problem: I need to implement zoom of this canvas somehow. I am zooming canvas (there is a grid drawn on it) and elements are zooming as well. It could be scaling (I know about quality after scaling bitmap, it's acceptable in my case). The only problem I don't really know how to solve is how to scale both canvas and independent elements which are over it, that we have an illusion that scene is scaling. Hope you've got the idea what I am trying to do.
If your target browsers support CSS3 transforms, you could apply a transform to your floating divs to match the one in the canvas, e.g. set style to transform: scale(1.5,1.5).
Note: you'll probably want the div wrapping the canvas and the absolute divs to have overflow: hidden so that you only show things in that area.
Related
I'm scaling a div (zoom functionality) on page with non-scaled divs. The scaled div has mouseover events that cause text to follow the mouse. Scaling breaks the position of the element that should follow the mouse.
Hover text is done like:
$("#container").on('mousemove','.mouseMe',function(e){
$("#followA").css("top",e.clientY)
.css("left",e.clientX);
});
//also some additional mouseenter/leave events are used to display hover
Scaling:
#container{
transform-origin: top left;
transform: scale(1.1,1.1);
}
I think what I need is to get the mouse's position on a css scaled div as if it wasn't scaled. (example: if the mouse is at the center of the div say [25,25], it should always return [25,25] even if the div is scaled). I could be wrong about what I need though, so the functional requirements take priority:
Element needs to follow mouse when hovered
Element container (or several containers up) needs to be scalable via css without breaking hovers (other transforms not relavant and no nested scaling)
JS, JQuery, CSS are all in use.
Chrome support is primary. Should also work in FF but not crucial. IE isn't supported.
This fiddle may explain this better and shows what doesn't work: http://jsfiddle.net/yvanaxe1/4/ (make the result pane big enough)
Is having those “follower” elements be descendants of the scaled element(s) an absolute requirement? Because, if you could take them out of there, and then simply position them over the top left edge of the mouseover-triggering element (by using the clientX/-Y values everywhere, plus some offsets to re-position them from there to appropriate distances), I think you might get there easier … http://jsfiddle.net/yvanaxe1/6/
I increased the scale value here, so that the effect on the follower elements (that the scaling has been applied to as well) is more obvious.
I've came across wunderlist.com site and just fell in love with the zoom-like pop-up they have on the image just beneath the header "Learn more about Wunderlist".
I'd love to implement something like this on my site.
Can somebody tell me how this is done? I tried to reverse-engineer, but with no luck :)
I'm not hoping for the whole ready code, but maybe some guidelines on how to achieve this with CSS/jQuery.
Or maybe you know some jQuery plugin that I could use?
They are using all CSS. Pretty simple really.. I would code a full js fiddle example for you but I don't have the time, so instead I will list out the different elements you need and how they interact.
First the large image is just a div with a background image with set
dimensions.
The circular images themselves are generated from one large image containing all of the circles in one spot, this is called a sprite. The circles are just div's with background images and background positioning to position the correct circle inside the box from the sprite image.
The text boxes themselves are also div's with a standard H2 and P tags for the text.
Everything is absolute positioned in order to achieve the proper layout.
The small circles are div's with :hover states that are absolute positioned over their respective targeted areas.
The animation on :hover is achieved by the use of css3 transition and css3 transforms.
This should get you started.
Comment if you have questions.
Had some time to have some fun: http://khill.mhostiuckproductions.com/siteLSSBoilerPlate/fun-experiment-mh/
Try looking at two main aspects:
Open up your inspector tool of choice and look at what happens to body.login .feature
...more specifically, look at what happens to its transform: scale and opacity values upon :hover.
Hint: the transition is mainly on them.
Still in your inspector, change the scale to (1) and the opacity to 1. How it smoothly gets from one state to the other is dictated by the transition property.
This isn't meant to tell you exactly how to achieve it, but to get you on your way :)
It's not that hard actually. The Wunderlist team has even made it easier. They have a large sprite image with the zoomed images cropped and ready with rounded corners, borders and shadows. You can see it here: https://wunderlist2.s3.amazonaws.com/179510ff7c929bfcc6e9819f3c2539baca5d3325/images/welcome-screen.png
What you do is on mouseover you show a half transparent black background (can be position: fixed with full width and height). Then you create a element with the sprite as the background image (even better, have a class ready in your css and append it to your newly created element). Set position to the position of the hovered element.
When added to the dom animate the transform scale of the element (starting with something like scale(.24) as they do).
Well since you tried reverse engineering. I'll try and guide you along that path.
There is only one div with id overlay which is changes it's place & content, on hover of any div with class feature. Work your way further from their app js, it's not minified.
The content of the popup in this case is an image moved to different positions.
I want a div to occupy view port when a user clicks on it. currently, I have set css3 transition to the div. And setting the width and height property using javascript. And animation happens. But it is not smooth. It looks jerky.
So, I want to use some built in function to scale. And I ended with css3 scale(). But it scales the content as well. I just want the div to expand. Not the content.
Is this is achievable or Is there any other way to do this? And I want to implement css3 solution not a javascript solution.
There is a hacky way to do this in pure CSS, which is to add an interior div to hold the content - then apply the scale up to the element and apply an equal scale down to the interior div itself. In this way, your content will stay the same size.
I plan on creating a layer of absolutely positioned elements that is moved around with jQuery. I need to create a frame, on top of and around this layer, that has a fixed viewport in the center and edges which flow to the edges of the browser viewport, creating a mask that hides portions of the main layer that is moved around underneath.
Currently I am using four divs to create the frame and setting their dimensions onload with a jQuery statement like this:
`$("#viewportLeft,#viewportRight").css("width",($(window).width()-[maskViewportWidth])/2);`
Any better ideas?
Why not just move a div around inside another div?
I have a container of some HTML divs and with some CSS if I hover over them, the background color changes. I want to overlay a canvas on top of the container so that I can draw lines. The problem is that when the canvas is overlaid, the hovering changes of the divs no longer works. Is there a way to overlay a canvas but still have CSS or JavaScript onmouseover events still work on the elements beneath?
So you want sort of a transparent canvas which passes all mouse events except clicks to the elements behind it?
IMHO, you'd need to use JS for that: Capture all the events on the canvas, then manually pass them on to the div behind the canvas. If you have multiple divs, you'd need some sort of lookup depending on the (x,y) coordinates of the mouse.
An alternative to going through all that hassle would be by using the pointer-events CSS attribute. Mozilla,Webkit and IE6-8(excanvas) all support this. Opera does not, but I really don't care.
<canvas style="pointer-events:none;"></canvas>