javascript - Jquery 动画最初在 Safari 中失败

标签 javascript jquery safari

我有一个画廊,单击缩略图时会执行一系列动画。其中一个动画——调整包含 block 的大小——在 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>

最佳答案

经过一番摆弄后,我采用了大锤解决方案:我使用 if ($.browser.webkit) 为 block 元素提供 Safari 像素宽度,而不是像 css 中的百分比。现在可以了!这对我来说已经足够了。 :)

关于javascript - Jquery 动画最初在 Safari 中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5556298/

相关文章:

ios - indexedDB 在 iOS 上表现不佳?

javascript - 无法在 Safari 中选择文本

Javascript - 无法实例化同一对象的多个实例

javascript - 找到控件的parent(),然后找到 ("a") JQuery

javascript - 将类 "last"添加到每个 div 编号 4 、 8 、 12 、 16 等

jquery - 单击表格行后如何刷新部分 View

html - safari flex 不适用于 clearfix hack

javascript - 这两种创建数组对象的方式之间的区别

javascript - jQuery 自定义插件更改应用于所有实例

javascript - Node Webkit-通过 outlook 打开和发送电子邮件