2

First my code:

Html

 <div class="product_image m2" id="m2"><a href="#" id="10" class='multi2'>test..</a></div>

JS

 $(document).ready(function(){

     $("#m2 a").bind("click", function() {
        var value = $( this ).attr( 'id' );
        alert(value);
        return false;
    });


    if ($(".multi2").length > 0){
    
           $(".multi2").yoxview({
           
                cacheImagesInBackground:true,
                skin: "top_menu",
                lang: "hu",
                
                images: [
        
                { media: { src: 'images/galeria/cella/image01'+value+'.JPG', title: 'Cella hegesztő' }},
                { media: { src: 'images/galeria/cella/image015.JPG', title: 'Cella hegesztő' }},
                { media: { src: 'images/galeria/cella/image013.JPG', title: 'Cella hegesztő' }},
            
            
            ]
            });
    }

 });

So, I use Yoxview. Multi2 class define the images and when user click on link (or thumbnail). lightbox shown and slideshow start.

The slideshow start every time from the first image defined in JS. I would like to change this so i would like to pass the id of href inside in m2 div to the image list.

Unfortunately I can't do this. I try this code but with this the script crash. How can I pass VALUE to image list?

2
  • 1
    you can not start id with a number , it is illegal Commented Aug 28, 2012 at 8:48
  • 2
    @KanishkaPanamaldeniya Not any more with html5 Commented Aug 28, 2012 at 9:11

1 Answer 1

2

Try code below, this probably will work, but not a good solution.

EDIT
By the way as Kanishka mentioned its not legal to start ID with a number. You can store photo id as an custom attribute <a href="#"... data-photoid="2" ... /> and get it using jquery data() $(this).data('photoid').

$(document).ready(function(){
     $("#m2 a").bind("click", function() {
        var value = $( this ).attr( 'id' );
            if(!$(this).data('yoxed')) {
                 $(this).yoxview({

                    cacheImagesInBackground:true,
                    skin: "top_menu",
                    lang: "hu",

                    images: [
                       { media: { src: 'images/galeria/cella/image01'+value+'.JPG', title: 'Cella hegeszto' }},
                       { media: { src: 'images/galeria/cella/image015.JPG', title: 'Cella hegeszto' }},
                       { media: { src: 'images/galeria/cella/image013.JPG', title: 'Cella hegeszto' }}
                    ]
                  });
                 $(this).data('yoxed', true).trigger('click');
            }
        }

        return false;
    });
});
Sign up to request clarification or add additional context in comments.

3 Comments

its works as a dream!!! But need to click twice on the link, 'coz the first click do nothing. Any idea about this behavior?
I edited the code. Try this one. Maybe its because yoxview attach an onclick handler after initialization, so you need to click again so that handler is dispatched.
the edited code not workin. But its not a big deal the two click.. I modify my code your Jquery Data() sugesstion.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.