JQuery does not work in IE 7 and Chrome

Well, I have enough code that I probably shouldn't post the code directly, but I'm not sure where the problem is in it.

This page is at letterlyyours.com/design.php. How it should work is that you enter a word, click "Submit", and then small photos of each letter will appear at the bottom - you can scroll up and down. In addition, if you click on a thumbnail, fancybox opens to show the full image.

The problem is that in Chrome, all scroll arrows are disabled. Also in IE 6/7 (it works in IE 8) fancybox only works for the first thumbnail in the list. Isn't that weird?

In any case, I suspect that the problem may have been caused by something hacky, which I had to do to fix another problem. For the list of photos, I initially used 2D arrays, for example, photos [4] [6], but this only worked in Firefox, so I changed it to something like eval ('photos' + number +' [index]), which seemed , made it work in IE, with the exception of the above problems.

Link to the file with all javascript code: http://letterlyyours.com/jcarousel/design.js.php

Here is the code:

photos0 = [
{url: "photos/thumb_A 1.jpg", title: "A 1"},
{url: "photos/thumb_A 2.jpg", title: "A 2"},
...
];
...
...
photos25 = [
{url: "photos/thumb_Z 1.jpg", title: "Z 1"},
...
];

jQuery(document).ready(function() {

jQuery('#create').submit(function(event) {
    var word = jQuery('#word').val();
    event.preventDefault();
    jQuery('ul').unbind();
    jQuery("#creation").html('');
    jQuery('#creation').css('width', Math.max(122, 75*word.length));
    for (var a = 0; a < word.length; a++)
        {
        jQuery('#creation').append('<ul class="jcarousel jcarousel-skin-tango" id="carousel' + a + '"></ul>');
        var total = eval('photos' + parseInt(word.toUpperCase().charCodeAt(a)-65) + '.length');
        for (var b = 0; b < total; b++)
            {
            var url = eval('photos' + parseInt(word.toUpperCase().charCodeAt(a)-65) + '[b].url');
            var url_full = url.replace('thumb_', '');
            jQuery('#carousel' + a).append('<li><a id="thumb' + b + '" href="' + url_full + '"><div style="width: 75px; height: 113px; background-image: url(\'' + url + '\');"></div></a></li>');
            jQuery('a#thumb' + b).fancybox({
                'transitionIn': 'elastic',
                'transitionOut': 'elastic',
                'hideOnContentClick': true
            });
            }       
        jQuery('#carousel' + a).jcarousel({
            vertical: true,
            scroll: 1,
            itemVisibleInCallback: function(carousel, li, index, state) {
                jQuery(li).parent().data('image', jQuery(li).children('a').children('div').css('background-image').replace(/"/g, ''));
            }
        });
        }
    jQuery('#creation').append('<a id="order" href="#orderform"><img width="122" height="24" src="images/button_order.png" tabindex="3" alt="Order Yours" /></a>');
    jQuery('a#order').fancybox({
    'hideOnContentClick': false,
    'transitionIn': 'fade',
    'frameWidth': 'auto',
    'title': 'Order \'' + word + '\'',
    'overlayShow': true,
    'overlayOpacity': 0.8,
    'overlayColor': 'black',
    'onStart': function() {
        jQuery('#list').html('');
        jQuery('#cost').html(word.length + ' photos at $6.00 per photo <br />Total: $' + word.length*6);
        jQuery('form#contact-form').unbind();
        jQuery('form#contact-form').submit(function(event) {
            jQuery.fancybox.showActivity();
            jQuery.post('contact.php', jQuery('form#contact-form').serialize(), function()
                {
                jQuery.fancybox(jQuery('div#thanks'));
                });
            event.preventDefault();
        });
        var photolist = '';
        for (a = 0; a < word.length; a++)
            {
            jQuery('#list').append('<div style="float: left; width: 75px; height: 113px; background-image: ' + jQuery('#carousel' + a).data('image') + '"/>');
            photolist += jQuery('#carousel' + a).data('image');
            }
        jQuery('#photonames').val(photolist);
        }
    });
});

jQuery('#word').keypress(function(event) {
    var letter = event.which;
    if ((letter != 8) && (letter != 0))
        {
        if (letter < 97)
            letter += 32;
        if (!((letter >= 97) && (letter <= 122)))
            {
            event.preventDefault();
            }
        }
});

jQuery('#word').select(function(event) {
    event.preventDefault();
});
});
+3
source share
2 answers

. IE, fancybox .

, fancybox , , , script, total - 1 IE7

var total = eval('photos' + parseInt(word.toUpperCase().charCodeAt(a)-65) + '.length');

, for, fancybox jQuery('a#thumb' + b). , , b < total ( b = 0).

IE, , , . :

var total = eval('photos' + parseInt(word.toUpperCase().charCodeAt(a)-65) + '.length');
alert('total = ' + total);

, , .

, fancybox, , CSS , , 'a#thumb' + b , , :

jQuery('a.thumbnail').fancybox({ .... });

, , ...

Chrome , Chrome, ?

+2

, . IE7

0

Source: https://habr.com/ru/post/1729102/


All Articles