0

I have a main panel hided at first, and sliding when the web runs. It has this style:

.contentPanel {    
    top: calc(40% - 1px);    
    height: 50%;  
    padding:10px;
    font-size:1.2em;
    overflow-y: scroll;
    overflow-x: hidden;
    left: 20%;
   width: 75%;
}

.contentPanel{

   transition: transform 5000ms cubic-bezier(0.095, 0.725, 0.020, 1.005); 
}

When the website runs, jQuery calculates window's width and hides it translating X out of the window:

  $('.contentPanel').css('left',window.innerWidth+"px");

And, theorically, CSS should bring it to it's correct position by adding the class .expanded:

$('.contentPanel').addClass('expanded');

Which takes it to it's 0% translate X position:

.expanded {
    transform: translate(0%);
}

Problem: CSS makes just nothing because jQuery styles .contentPanel on its HTML tag, like this:

<div class="contentPanel expanded" style="left: 1366px;">

And even thow a translateX(0%) is being added, nothing moves due to the fact that X px are given on HTML's opening tag atribute.

3 Answers 3

1

I would make a wrapper that is 100% width (which is default) that you can utilize to hide .contentPanel. This way you only need toggle the class and not mess with $.css() at all.

http://jsfiddle.net/M8PQR/

HTML

<div class="wrapper">
    <div class="contentPanel"></div>
</div>

<a class="toggle">show/hide</a>

JAVASCRIPT

var $wrapper = $('.wrapper');

$('a.toggle').on('click', function() {
    $wrapper.toggleClass('expanded');
});

CSS

.contentPanel {    
    top: calc(40% - 1px);    
    height: 50%;  
    padding:10px;
    font-size:1.2em;
    overflow-y: scroll;
    overflow-x: hidden;
    margin: auto;
   width: 75%;
    background: deepSkyBlue;
}

.wrapper{
    transform: translate(100%);
    transition: transform 5000ms cubic-bezier(0.095, 0.725, 0.020, 1.005);
}

.wrapper.expanded {
    transform: none;
}

.toggle {
    cursor: pointer;
}
Sign up to request clarification or add additional context in comments.

4 Comments

That is a good answer. I did that before asking, and there are two reasons why I'd like to make it in other way:
- there are 7 elements under this situation, each one with a separate animation and div, and 7 fullscreen divs on screen are very hard to navigate trough Firebug, for example. - links and buttons on any screen not being the first one were invalid, as those could not be clicked because the last of all fullscreen divs was the only one that could intercat with the user
Well you could just use 7 wrappers?
Yes. But when the 7 are loaded an positioned, just the links and buttons placed on the last one added will be clickable. All the rest will be on deeper wallpapers and interaction of those with the user (click on a link, for example) will not be possible. I am about to try your method anyway and tell you then.
0

Inline style has a higher priority. Try setting the left property to blank before adding a class "expanded". Like so:

$('.contentPanel').css('left',''); 
$('.contentPanel').addClass('expanded');

1 Comment

Hi Ivan. Nope. As it is hidden due to it's element style given by jQuery, when taking that style out it just appears on screen without the sliding effect (it goes from 1366px to 0 without transition animation). Then when adding .expanded, it was already on its place
0

Couldn't you set left to auto before adding the .expanded class?

$('.contentPanel').css('left', 'auto').addClass('expanded');

That said, I think Michael's solution is the best over all.

EDIT

Or you can set .contentPanel to transform: translateX(-100vw), as the poster seems to prefer.

VW has pretty good support now. I would avoid VH for the time being, though, because VH is buggy in mobile Safari.

6 Comments

Nope. Auto left makes it go to the left without any margin and without animation.
Why not take a different approach and have .contentPanel automatically translated offscreen. Set it to a sufficiently large value (e.g., 5000px) .contentPanel { transform: translateX(-5000px); } and then have .contentPanel.expanded set to { transform: initial; }. If you're worried about the animation not being smooth because of the distance, setting up a custom easing curve should mitigate that problem.
Thats also a solution but I think that would bve last option to get this. A TV will have more that 5000 px, and if we have methods to have in mind all possible situations, those should be fist tried. But I am very grateful for your help.
You could also say transform: translateX(-100vw) if that's a concern.
Ops... caniuse.com/viewport-units many people coming from a mobile device will not have needed broweser version.. maybe detectig if it's a mobile device and setting a -1000px translation for those, and -100vw for the rest would be the best solution
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.