Jquery动画最初在Safari中失败

时间:2011-04-05 17:59:23

标签: javascript jquery safari

我有一个库,当点击缩略图时会执行一系列动画。其中一个动画 - 包含块的大小调整 - 在IE / Firefox中按预期工作,但最初在Safari中失败,然后在后续点击时按预期工作。在网站的“安装”页面上使用类似脚本的图库遇到了同样的问题,只是它无法计算出正确的宽度。

我已尝试从$(document).ready()切换到$(window).load()但未成功。我迫切希望找到解决方案;由于这个问题,这个项目被推迟了,我不是开发人员,所以我没有第一个线索可能会出错。我会非常感激任何帮助。

Here's a link to the live site。有问题的代码如下:

$(window).load(function() {
            $('#back').hide();
            $('#full-wrap').hide();
            $('#thumb-wrap a').children().not('img').hide();//hide image captions

            var moveIt = $('#thumb-wrap').outerWidth(); //Get the width of the thumb-wrap div
            /*if ($.browser.webkit) {
                    var moveIt = $('#thumb-wrap').css({width: '100%'});
                    $('#full-wrap').width(383);
                }*/

            $('#thumb-wrap a').click(function(){

                var $big = $(this).index(); //get 0-based index of the thumb that was just clicked
                $('#ajax-content > h1').hide();//hide the page title
                $('#thumb-wrap').hide(); //hide the thumbnails
                $(this).children().not('img').clone().appendTo($('#gallery-wrap')).wrapAll('<div class="article"/>').delay(600).fadeIn(); //Clone the image captions and wrap them in an article
                $('#back').fadeIn(500); //make the back button appear

                $('#full-wrap img').eq($big).siblings().hide(); //Hide all fullsized images that don't match the index of the clicked thumb
                $('#full-wrap img').eq($big).show(); //reveal fullsized image that does match the index of the clicked thumbnail


                $('#content').animate({'maxWidth': '+=' + moveIt * 0.5 + 'px', 'left': '6%'}, 'slow');
                $('#full-wrap').show(100).animate({ 'right': '+=' + moveIt * 0.75 + 'px'}, 'slow'); //slide out by a distance equal to the width of thumb-wrap.

            });

            $('#back').click(function(){
                $(this).fadeOut();//hide the back button
                $('.article').remove();//remove the article div
                $('#full-wrap').animate({'right': '0', 'opacity' : 'toggle'}, 400);//hide the fullsize image div
                $('#content').animate({'maxWidth': moveIt, 'left' : '43%'}, 400);
                $('#thumb-wrap').delay(500).fadeIn(500);//reveal the thumbnails
                $('#ajax-content > h1').delay(500).fadeIn(100);//show the page title

            });

         });


<div id="gallery-wrap">
    <a href="#" id="back"><h3>Back</h3></a>
    <div id="thumb-wrap">
        <a href="#">
            <img src="http://www.qp2creative.com/clients/dfrank/images/11t.jpg" alt="DC1F" />
            <h1>DC1F</h1>
            <p>Material: Merino wool, raw silk, silk gauze, cashmere, wild silk, raw linen and silk yard.</p>

        </a>

        <a href="#">
            <img src="http://www.qp2creative.com/clients/dfrank/images/6t.jpg" alt="DC2F" />
            <h1>DC2F</h1>
            <p>Material: Merino wool, silk organza, and wild silk.</p>
        </a>

        <a href="#">
            <img src="http://www.qp2creative.com/clients/dfrank/images/10t.jpg" alt="DC3F" />

            <h1>DC3F</h1>
            <p>Material: Silk organza, merino wool, handspun wool and silk, and raw silk. Dyed with color derived from weld.</p>
        </a>

        <a href="#">
            <img src="http://www.qp2creative.com/clients/dfrank/images/8t.jpg" alt="DC4F" />
            <h1>DC4F</h1>
            <p>Material: Merino wool, silk organza, raw silk, raw linen, and Wensleydale wool. Dyed with color derived from onion skins. </p>

        </a>

        <a href="#">
            <img src="http://www.qp2creative.com/clients/dfrank/images/18t.jpg" alt="DC5F" />
            <h1>DC5F</h1>
            <p></p>
        </a>

        <a href="#">
            <img src="http://www.qp2creative.com/clients/dfrank/images/9t.jpg" alt="DC6F" />

            <h1>DC6F</h1>
            <p>Material: Merino wool, silk chiffon, raw silk, and raw linen.</p>
        </a>

        <a href="#">
            <img src="http://www.qp2creative.com/clients/dfrank/images/22t.jpg" alt="DC7F" />
            <h1>DC7F</h1>
            <p>Material: Natural yak hair, merino wool, raw silk, and handspun silk.</p>

        </a>

        <a href="#">
            <img src="http://www.qp2creative.com/clients/dfrank/images/23t.jpg" alt="DC9F" />
            <h1>DC9F</h1>
            <p>Material: Merino wool, raw silk, silk organza, and raw linen.
Dyed with color derived from weld.</p>
        </a>

        <a href="#">
            <img src="http://www.qp2creative.com/clients/dfrank/images/19t.jpg" alt="DC10F" />

            <h1>DC10F</h1>
            <p>Material: Merino wool, silk chiffon, and raw silk. Yellow is dyed with color derived from weld.</p>
        </a>
    </div>
        <div id="full-wrap">
            <img src="http://www.qp2creative.com/clients/dfrank/images/11.jpg" alt="DC1F" />

            <img src="http://www.qp2creative.com/clients/dfrank/images/6.jpg" alt="DC2F" />

            <img src="http://www.qp2creative.com/clients/dfrank/images/10.jpg" alt="DC3F" />


            <img src="http://www.qp2creative.com/clients/dfrank/images/8.jpg" alt="DC4F" />

            <img src="http://www.qp2creative.com/clients/dfrank/images/18.jpg" alt="DC5F" />

            <img src="http://www.qp2creative.com/clients/dfrank/images/9.jpg" alt="DC6F" />

            <img src="http://www.qp2creative.com/clients/dfrank/images/22.jpg" alt="DC7F" />

            <img src="http://www.qp2creative.com/clients/dfrank/images/23.jpg" alt="DC9F" />

            <img src="http://www.qp2creative.com/clients/dfrank/images/19.jpg" alt="DC10F" />
    </div>

1 个答案:

答案 0 :(得分:0)

经过一番摆弄后,我选择了大锤解决方案:我使用if ($.browser.webkit)来提供块元素的Safari像素宽度与css中的百分比。现在它有效!这对我来说已经足够了。 :)