Rotate css3 bug - css

I'm making a 3d cube based on http://www.paulrhayes.com/experiments/cube-3d/
but mine react on mouse event and touch event on mobile.
I introduce RotateZ to evitate the strange behaviour of the original Hayes cube.
But when if i try to go left -> down and left again it bug.
-webkit-transform:rotateX(-90deg) rotateY(-90deg) rotateZ(0deg);
RotateX and Z make move cube on the same axis I don't know why.
Does it a bug or there is a solution ?
here's is a detailled jsfiddle of my problem :
http://jsfiddle.net/uq2cr/6/
Thank's for your answers !

Problem
This is because when you move the mouse up/down, whilst moving left/right and clicking it will reside to the up/down action.
Current Strucutre
I benchmarked the update of x co-ords.
For both left and right directions, x 0, doesn't seem relative.
The xAngle, yAngle, zAngle increment, but do not reset to 0.
Suggestion
I suggest making some changes to the structure of cubePointerMove(). Make each direction their own stack. That way, there will be no forthcoming problems with the 4 directions.
The way it's set out now, is with duplicate up/down actions in the left/right blocks.
Current
// Left
if( xMove < 0) {
// Up
if( yMove < 0 ) {
if(xMove < yMove){
}
}
// Down
else {
}
}
// Right
else
{
}
Revised
// Up
if( yMove < 0 ) {
}
// Down
else {
}
// Left
if( xMove < 0) {
}
// Right
else {
}

Related

Why mousewheel event is not working some times with my code?

I'm trying to make a fullpage component in Angular :
I want each sections take a 100% height of my screen, and when I scroll in a section (up or down) it goes to the next / previous section. I declared this function to do that, and it works :
#HostListener('wheel', ['$event'])
onScroll(event: WheelEvent) {
if (event.deltaY < 0) {
this.slidePrev();
} else {
this.slideNext();
}
}
Now, I want to update a little to slide to the previous slide only if the scrollbar is on the top, or slide to the next only if the scrollbar is to the bottom. I Used JQuery to do that, this way :
#HostListener('mousewheel', ['$event'])
onScroll(event: WheelEvent) {
if (this.isSliding) {
event.preventDefault();
return;
}
let $section = $(event.target).closest(".section");
//$section.css("opacity", "0.99");
//setTimeout(() => {
// $section.css("opacity", "1");
//}, 100);
if (event.deltaY < 0) {
if ($section.scrollTop() == 0) this.slidePrev();
} else {
if ($section.scrollTop() == $section.prop("scrollHeight") - $section.height()) this.slideNext();
}
}
It works the first time, but if I slide down to the next slide, when I want to sroll to move my scrollbar, it doesn't move.
I noticed that after the website trigger an update (example : css :hover event that update style) the scrollbar move again. So, if I uncomment my 4 commented lines, it works again because the style is updated.
Can someone tell me why ? And is there a better way to fix that issue ?
EDIT :
in slideNext() and slidePrev() I'm using $().animate("scrollTop", ...) function, and it's the function that breaks my scroll

How to know if a scroll bar is visible on a JavaFx TableView

Is there a way to know if a scroll bar is present on a table view? (Other than what I did in my code below)
My goal is to position 2 arrow images (to close/open a side panel) on the right side of a table (over the table.). But I don't want to put them over the scroll bar.
The table content is a result of a search, so sometime the scroll bar is visible and other time it is not. If there is not enough items.
I want the position of my arrows to change every time the tableview items change.
I already try the following solution, but the result is that the arrows are moved the second time I do the search. Looks like a concurrency problem. Like if my listener code is executed before the table is rendered.
Is there a way to solve that?
tableView.getItems().addListener( (ListChangeListener<LogData>) c -> {
// Check if scroll bar is visible on the table
// And if yes, move the arrow images to not be over the scroll bar
Double lScrollBarWidth = null;
Set<Node> nodes = tableView.lookupAll( ".scroll-bar" );
for ( final Node node : nodes )
{
if ( node instanceof ScrollBar )
{
ScrollBar sb = (ScrollBar) node;
if ( sb.getOrientation() == Orientation.VERTICAL )
{
LOGGER.debug( "Scroll bar visible : {}", sb.isVisible() );
if ( sb.isVisible() )
{
lScrollBarWidth = sb.getWidth();
}
}
}
}
if ( lLogDataList.size() > 0 && lScrollBarWidth != null )
{
LOGGER.debug( "Must move the arrows images" );
tableViewController.setArrowsDistanceFromRightTo( lScrollBarWidth );
}
else
{
tableViewController.setArrowsDistanceFromRightTo( 0d );
}} );
I assume you know that it is not a good idea to rely on the internal implementation of TableView. Having said that, you're code looks mostly good (I did a similar thing for an infinite scrolling example).
However you should also consider the case that the scrollbar may appear due to the main window changing its size.
I would therefore suggest you listen to changes in the visibilty-property of the scrollbar.
private ScrollBar getVerticalScrollbar() {
ScrollBar result = null;
for (Node n : table.lookupAll(".scroll-bar")) {
if (n instanceof ScrollBar) {
ScrollBar bar = (ScrollBar) n;
if (bar.getOrientation().equals(Orientation.VERTICAL)) {
result = bar;
}
}
}
return result;
}
...
bar.visibleProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
// tableViewController.setArrowsDistanceFromRightTo(...)
}
);

Three.js rotate camera to specific position

I have an sphere with divs using CSS3DRenderer. When I click to one of the divs I'd like to position/rotate the camera so the element displays in the center of the screen.
I've tried several examples and I've read other answers but still I cant get it to work.
At the moment it moves the camera but the sphere gets repositioned in different places
What I'm trying to do is the following:
Gets the HTML element's class. Then loop through an array of THREE.CSS3DObject to get its position, then use that to position the camera.
function moveCamera(element) {
for ( var i = 0; i < objects.length; i ++ ) {
var object = objects[ i ];
if(object.element.className == element.className) {
position = object.position;
rotation = object.rotation;
found = true;
break;
}
}
if (found) {
camera.rotation = rotation;
render();
found = false;
} }
What I'm I doing wrong?
Here's the example http://jsfiddle.net/37R22/1/
Thanks
You were close. You just have to move the camera to the right place.
camera.rotation.copy( rotation );
camera.position.copy( position ).multiplyScalar( 4 );
Updated fiddles: http://jsfiddle.net/37R22/2/ or http://jsfiddle.net/37R22/3/
Be careful about going behind-the-back of TrackballControls and modifying the camera properties yourself. This appears to work, however.
three.js r.65

CSS Position Fixing

I have managed to use the position:fixed setting of CSS/CSS3 before and worked quite well!
I saw this a few days ago and was wondering how did they achieve the effect that happens when you scroll down, where the menu bar is in one position before you scroll and then goes to the top where it locks itself down.
See link - http://www.cssportal.com/ < scroll down on any page and observe the top blue menu.
I have tried to look in the source of the page but I cant make head or tails.
Does anyone know what this effect is called?
It's done with javascript, to add a css class that contains position:fixed and other positioning styles to achieve what you want.
It's not complicated. Here is a jquery plugin: http://stickyjs.com/
This is how I did it a few years ago:
var menu_bar = $("#menu");
var top = menu_bar.offset().top;
var detached = false;
$(window).scroll(function (e) {
if ($(this).scrollTop() >= top) {
if (!detached) {
detached = true;
menu_bar.addClass('fixed');
}
} else {
if (detached) {
detached = false;
menu_bar.removeClass('fixed');
}
}
});

Returning a CSS element (for use in boundary checking)

Is there a way to return a CSS element?
I was using Adobe Edge and adding some of my own code in their code tab, but in order to create boundaries I would need to keep track of margin-top or margin-left. The following code works to move the element "woo" but I'm not sure how to call the elements to add something like "|| sym.$("woo").css({"margin-left">0px"}) to the move left code.
//Move RIGHT
if (e.which == 39) {
sym.$("woo").css({"margin-left":"+=10px"});
}
//Move UP
else if (e.which == 38) {
sym.$("woo").css({"margin-top":"-=10px"});
}
//Move Left
else if (e.which == 37) {
sym.$("woo").css({"margin-left":"-=10px"});
}
//Move DOWN
else if (e.which == 40) {
sym.$("woo").css({"margin-top":"+=10px"});
}
EDIT:
I changed the Left if statement to the following:
else if (e.which == 37 && ($("woo").css("margin-left")>0)) {
It seems to be working to some extent except for now it won't move left at all! I tried doing <0 too in case I was screwing up a sign but it won't let me move the element left either.
ANSWER:
Well it turns out that the syntax of returning values is a little different than i thought. To return the left margin instead of using the dash like how i used to set it, I had to do as below.
sym.$("woo").css('marginLeft')
And then to actual make it an int and compare it I used this.
if(parseInt(sym.$("woo").css('marginTop'))>0)
You can get the value of a CSS property by calling the .css() method:
$(...).css('margin-left')
Well it turns out that the syntax of returning values is a little different than i thought. To return the left margin instead of using the dash like how i used to set it, I had to do as below.
sym.$("woo").css('marginLeft')
And then to actual make it an int and compare it I used this.
if(parseInt(sym.$("woo").css('marginTop'))>0)

Resources