代码之家  ›  专栏  ›  技术社区  ›  Shadi Almosri

在webkit浏览器中,JQuery可滚动的缺失位置onload和api seek

  •  1
  • Shadi Almosri  · 技术社区  · 16 年前

    我在工作中遇到了一个奇怪的问题 this 在右下角是一个历史部分,有一个左右移动的可滚动部分。加载时,它选择一个随机数并移动到它。

    问题是加载时(不移动)加载到错误的位置,而使用api移动时则移动到错误的偏移位置(正确的图像只是没有正确定位)。这个问题只发生在 浏览器( 游猎 和 铬 )

    任何帮助都将非常感谢,因为我似乎无法了解这个IE和FF行为良好奇怪的底部!:(

    JavaScript :

    $(document).ready(function(){
        $('.timeline-container').scrollable({circular: true, next: ".timeline-next", prev: ".timeline-prev"});
        var api_timeline = $(".timeline-container").data("scrollable");
        //console.info(api_timeline.getSize());
        var timeline_random_index = Math.floor( Math.random() * ( api_timeline.getSize()+1) )+1;
        //console.info(timeline_random_index);
        api_timeline.move( timeline_random_index, 1000 );
    });
    

    <div class="timeline-container">
        <div class="timeline-items">
            <div class="timeline-item">
                <img src="http://identica.local/wp-content/uploads/2010/10/timeline_thumb01.png" />
                <p><span class="timeline-item-date">1996</span> Russian Flag carrier Aeroflot created</p>
            </div>              
            <div class="timeline-item">
                <img src="http://identica.local/wp-content/uploads/2010/10/timeline_thumb02.png" />
                <p><span class="timeline-item-date">1997</span> Universal Studios created</p>
            </div>              
            <div class="timeline-item">
                <img src="http://identica.local/wp-content/uploads/2010/10/timeline_thumb03.png" />
                <p><span class="timeline-item-date">1998</span> Vodafone brand refresh</p>
            </div>              
            <div class="timeline-item">
                <img src="http://identica.local/wp-content/uploads/2010/10/timeline_thumb04.png" />
                <p><span class="timeline-item-date">1998</span> Wembley Stadium identity created</p>
            </div>              
            <div class="timeline-item">
                <img src="http://identica.local/wp-content/uploads/2010/10/timeline_thumb05.png" />
                <p><span class="timeline-item-date">2000</span> Jonnie Walker brand created</p>
            </div>              
        </div>              
    </div>
    

    .timeline-container {overflow:hidden; width: 245px;position:relative; min-height: 170px;height: 170px !important;}
    .timeline-container .timeline-items { width:20000em; position:absolute;}
    .timeline-container .timeline-item {float:left;text-align:center;position: relative;}
    .timeline-container .timeline-items p { font-weight: normal; font-size: 13px; margin-bottom:0;}
    .timeline-container .timeline-items span { font-weight: bold;}
    

    更新

    真的很奇怪,我把这件事搞砸了 jsFiddle

    更新2

    我只是在某种程度上“修复”了它,但它是一个肮脏的小黑客-不理想,但工作:

    $(document).ready(function(){
        $('.timeline-container').scrollable({circular: true, next: ".timeline-next", prev: ".timeline-prev"});
        var api_timeline = $(".timeline-container").data("scrollable");
        var timeline_random_index = Math.floor( Math.random() * ( api_timeline.getSize()+1) )+1;
        var timeline_random_index_pixles = timeline_random_index * 245 * -1;
        $(".timeline-items").css("left", timeline_random_index_pixles+"px")
    });
    
    1 回复  |  直到 16 年前
        1
  •  0
  •   Shadi Almosri    16 年前

    通过在加载时使用自定义定位而不是可滚动函数修复。

    $(document).ready(function(){
        $('.timeline-container').scrollable({circular: true, next: ".timeline-next", prev: ".timeline-prev"});
        var api_timeline = $(".timeline-container").data("scrollable");
        var timeline_random_index = Math.floor( Math.random() * ( api_timeline.getSize()+1) )+1;
        var timeline_random_index_pixles = timeline_random_index * 245 * -1;
        $(".timeline-items").css("left", timeline_random_index_pixles+"px")
    });