0

端に近いスクロールソリューションで問題が発生しているようです。すでにドラッグしてスクロールするソリューションが実装されています。

これが私のコードです:

デモ1(現在のページ):http://jsfiddle.net/SO_AMK/FdLZJ/

デモ2(私が試したこと):http://jsfiddle.net/SO_AMK/8CCeA/

HTMLの抜粋:

<section class="row">
        <div class="scroll-left" style="opacity: 0;"></div>
        <div class="row-scroll">
            <div class="tile">
                <img class="tile-image" src="http://cache.gawker.com/assets/images/lifehacker/2011/08/1030-macpack-notational-velocity.jpg" />
                <title class="tile-title">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor...</title>
            </div>
            .....
            <div class="tile">
                <img class="tile-image" src="http://cache.gawker.com/assets/images/lifehacker/2011/08/1030-macpack-notational-velocity.jpg" />
                <title class="tile-title">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor...</title>
            </div>
        </div>
        <div class="scroll-right" style="opacity: 0;"></div>
    </section>
    <section class="row">
        <div class="scroll-left" style="opacity: 0;"></div>
        <div class="row-scroll">
            <div class="tile">
                <img class="tile-image" src="http://cache.gawker.com/assets/images/lifehacker/2011/08/1030-macpack-notational-velocity.jpg" />
                <title class="tile-title">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor...</title>
            </div>
            .....
            <div class="tile">
                <img class="tile-image" src="http://cache.gawker.com/assets/images/lifehacker/2011/08/1030-macpack-notational-velocity.jpg" />
                <title class="tile-title">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor...</title>
            </div>
        </div>
        <div class="scroll-right" style="opacity: 0;"></div>
    </section>

jQuery:

    $(document).ready(function () {       
        var pos = 5;

        $.fn.loopingScroll = function (direction, scrollElement) {

            if (direction == "right") {
                pos+=5;
            }

            else if (direction == "left") {
                pos-=5;
            }
            $(scrollElement).parent().scrollLeft($(scrollElement).parent().data('scrollLeft') + pos);
            return this;
        }

        $(".scroll-left").hover(function(){
        scrollLeftLoop = setInterval(function(){ 
            $(this).loopingScroll("left", this); 
            }, 25);
            $(this).fadeIn('fast');
        }, function() { clearInterval(scrollLeftLoop); $(this).fadeOut('fast'); });

        $(".scroll-right").hover(function(){
           scrollRightLoop = setInterval(function(){ 
              $(this).loopingScroll("right", this); 
          }, 25);
            $(this).fadeIn('fast');
        }, function() { clearInterval(scrollRightLoop); $(this).fadeOut('fast'); });
});

それは(行く!)Pulseの代替/ WebAppであると想定されているので、デザイン(私はフォントに取り組んでいます)。

何か案は?

前もって感謝します。

4

2 に答える 2

3

さて、少し頭を叩いた後、私はこれを思いついた:

$(".scroll-left").hover(function() {
    $(this).parent().animate({scrollLeft: 0}, 7000);
    $(this).fadeIn('fast');
}, function() {
    $(this).parent().stop();
    $(this).fadeOut('fast');
});

$(".scroll-right").hover(function() {
    $(this).parent().animate({scrollLeft: $(this).siblings(".row-scroll").width()}, 7000);
    $(this).fadeIn('fast');
}, function() {
    $(this).parent().stop();
    $(this).fadeOut('fast');
});

基本的にscrollLeft関数を使用し、スクロール要素の幅をオンザフライで計算して、値へのスクロールとして使用します。これは、このコードを示すJSFiddleです

誰かがこれを利用してくれることを願っています。私は質問の名前を適切に変更しています。

于 2012-07-12T23:33:15.800 に答える
0

手遅れだとは思いますが、他の誰かが助けを必要としているなら、彼らは解決策を得ることができます。アニメーションループにこれを試してください

function loopl(){
    $('.mCSB_container').animate({ "left": "+=80px" }, "800", 'linear', loopl  );
}        
function loopr(){
    $('.mCSB_container').animate({ "left": "-=80px" }, "800", 'linear', loopr  );
}
function stop(){
    $('.mCSB_container').stop();
}
$( "#left" ).hover(loopl, stop);
$( "#right" ).hover(loopr, stop);
于 2015-10-07T09:51:39.360 に答える