Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assign next/prev to my own buttons #68

Closed
fourgood opened this issue Feb 27, 2012 · 14 comments
Closed

assign next/prev to my own buttons #68

fourgood opened this issue Feb 27, 2012 · 14 comments

Comments

@fourgood
Copy link

is it possible to assign the next/prev to my own button. for example if i want the navigation to appear somewhere else on the page and not beneath the slides but under?

@Mottie
Copy link
Contributor

Mottie commented Feb 27, 2012

You can use the methods described in the wiki documentation to change panels from outside of MovingBoxes. Here is a demo, and the code below. Note that I used buttons in the demo but used links here for more variety.

HTML

<a href="#" class="prev">Previous</a>
<a href="#" class="next">Next</a>

Code

$('.prev, .next').click(function(){
    var slider = $('#slider').data('movingBoxes'),
        target = slider.curPanel += ($(this).hasClass('next')) ? 1 : -1;
    // change to panel #
    slider.change(target);
    return false; // don't follow the link
});

@fourgood
Copy link
Author

ahh, i knew i saw that example but just couldnt find it anymore.
any hint how i can put the left/right arrows beneath the nav which is generated dynamically?

edit: i tried with

<script> $('.mb-controls').prepend('PREV').append('NEXT'); </script>

but it shows only a second then disappears

@Mottie
Copy link
Contributor

Mottie commented Feb 27, 2012

Oh, I just made that demo... I don't think I made it before, unless you're referring to one of my AnythingSlider demos. o.O

I didn't test it, but I bet the arrows you added are disappearing because of all of the overflow: hidden settings and the alignment in the css,

Are you trying to add the navigation arrows in the same line as the navigation? Or, maybe try adding the arrows after the slider?

$('#slider').after('<a class="prev_btn">PREV</a> <a class="next_btn">NEXT</a>');

@fourgood
Copy link
Author

i meant that demo you were refering to ;)
i just want two little arrows on the left and right of the nav, like this ◁ ● ● ● ● ● ▷

@Mottie
Copy link
Contributor

Mottie commented Feb 27, 2012

Ahhh ok. Because the plugin looks for <a> within the navigation controls to determine which panel to choose, I had to use spans. Here is a updated demo

CSS

/* hide big arrows */
a.mb-scrollButtons { display: none; }
.mb-controls span {
    padding: 2px;
    margin-right:5px;
    cursor: pointer;
}
.mb-controls span:hover {
    color: #fff;
}

Script

$('#slider').movingBoxes({
    buildNav: true,

    // e = event, slider = MovingBoxes Object, tar = current panel #
    // callback when MovingBoxes has completed initialization
    initialized: function(e, slider, tar) {
        slider.$nav
            // we can't use <a> for the arrows since the plugin looks for
            // links within the navigation controls
            .prepend('<span class="prev">◁</span>')
            .append('<span class="next">▷</span>')
            .find('.prev, .next').click(function() {
                slider[ ($(this).hasClass('next')) ? 'goForward' : 'goBack']();
            });
    }
});

@fourgood
Copy link
Author

the <a> was the problem..thank you!

@Mottie Mottie closed this as completed Feb 27, 2012
@fourgood
Copy link
Author

can i append the buttons before initializing? i takes about 2-3 seconds until the arrows appear.

@Mottie
Copy link
Contributor

Mottie commented Feb 27, 2012

You can't really do that because the navigation links haven't been built yet. And if you did add them before initialization, they would get over-written by the navigation formatter. It's slow because the initialization callback isn't executed until all of the images have loaded.

@Mottie
Copy link
Contributor

Mottie commented Feb 27, 2012

Hmm, I guess I could add another callback and call it something like "preinitialization"... and have it occur after the basic structure is established.

@fourgood
Copy link
Author

tell me if you do. this script is getting better and better!

@Mottie
Copy link
Contributor

Mottie commented Feb 27, 2012

Ok done... I added a "preinit" callback. I'll update the docs in a bit (after lunch).

New demo that now allows using <a> links instead of spans :)

Also, I updated the navFormatter so you can add attributes to the nav links, like titles for tooltips or other data.

@fourgood
Copy link
Author

preInit is working well, no delay!

That new navFormatter seems to be a great feature but i can`t get it to work.
even that simple code :

navFormatter : function(index, panel){ return "&#9679;"; } 

doesnt work anymore. there are just numbers.

ive had some HTML in there which is not working anymore, too.

navFormatter : function(index, panel){ 

_title=panel.find('span').text();  _url=panel.find('a img').attr('src');

return "<div class='formInfo' id='"+_title+"' title='"+_title+"'>
        <div class='nav_btn'></div>
            <span style='display: none'>
                <img width='60' height='60' class='imag' src='"+_url+"' /><br />"+_title+"
            </span>
        </div>";  },

@Mottie
Copy link
Contributor

Mottie commented Feb 28, 2012

DERP!

I copied the navFormatter code from AnythingSlider and in that plugin, the option is named navigationFormatter... so I fixed the spelling. That'll teach me not to test my fixes :/ But it should be working now in the latest update! Sorry!

@Mottie
Copy link
Contributor

Mottie commented Feb 28, 2012

LOL I did it again.. the navFormatter was sending a zero-based index... I just fixed that. So now I think I've fixed all of the problems I introduced from yesterday's work. At least for this plugin o.O LOL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants