CSS-Tricks / MovingBoxes

Simple horizontal slider which grows up the current box when it's in focus (image, title & text) and back down when it's not in focus.
http://css-tricks.github.io/MovingBoxes/
GNU Lesser General Public License v3.0
280 stars 147 forks source link

Save current panel #72

Closed fourgood closed 12 years ago

fourgood commented 12 years ago

Is it possible to store the current panel in a variable to come back and see the same panel ? For example if i scroll to a certain panel (wordpress post) and click on it, the single view opens. now if i go back the first panel or the one i specified is visible, but not the one that ive clicked.

Mottie commented 12 years ago

What do you mean by a single view opens? Like a light box? If the light box has a closing callback, then you can specify in the callback which panel to go to. For example, Colorbox has a "onClosed" callback which you can use to change the panel MovingBoxes is currently displaying.

// clicking on any image inside the slider will open colobox
$('#slider img').colorbox({
  // colorbox closed callback
  onClosed : function(){
    var mb = $('#slider').data('movingBoxes');
    // go to the first panel
    mb.change(1);
  } 
});
fourgood commented 12 years ago

What ive meant is the single post view of wordpress. a new page opens. And when i come back to the slider. I want the last active panel (on which i have clicked) to be active again.

maybe "startPanel" have to be filled with a variable which is set via cookie or POST/GET.

Mottie commented 12 years ago

Umm, are you using the hash tags?... I'm not too good with Wordpress, so do you mean it's opening a new browser window (not a tab) or is it switching the current tab location? I guess I'm not picturing what you mean... what panel is showing when you come back to the slider, and if it switched, why would it switch?

fourgood commented 12 years ago

i just meant that if i click on a slide, the page changes from index.html to project1.html to show more information. if i then come back to the slider by clicking HOME on the menu, the slide that wascurrent when i clicked should be there again and not the default one.

fourgood commented 12 years ago
    <script>
    $(document).ready(function() {
        $('.mb-panel.current .mb-inside a').click(function(){
            var curr-panel = $('#slider').data('movingBoxes').currentPanel();
            $.cookie('current-panel', curr-panel, { expires: 30, path: '/' });
        });
    });
    </script>

so this is what i tried so far. but it seems to work only at the very first moment when the page is still loading.

and then i need something like:

        startPanel: $.cookie('current-panel');,

but i dont know how to grab this cookie there and furthermore the cookie function is still not working right.

edit: ok this seems to be working

startPanel: $.cookie('current-panel'), // Without the semi-colon,

but there is still the problem of the cookie creation

fourgood commented 12 years ago

ok working now! problem was the jQuery Selector.

    <script>
    $(document).ready(function() {
        $('a').click(function(){
            var mb = $('#slider').data('movingBoxes').currentPanel();
            $.cookie('current-panel', mb, { expires: 1, path: '/' });
        });
    });
    </script>

now ive only took 'a' as the selector, which updates the cookie everytime a slide or even a menu-link on the page is clicked. the advantage of this is, that it saves the current panel, no matter where i navigate. if i come back to the sliderpage the same panel is active again.

This can be closed.

Mottie commented 12 years ago

Nice work! Actually you can close issues too, I was just asking before because I wanted to make sure everything had been resolved ;)