简体   繁体   English

jQuery水平滚动条消失

[英]jquery horizontal scroll bar disappearing

I am currently building a website that has a jquery horizontal scroll box / bar. 我目前正在建立一个具有jquery水平滚动框/栏的网站。

The thing is I want to go all the way right and left every so often around every 5 seconds. 问题是我想每隔5秒左右走一次。

Here the jquery we are using 这是我们正在使用的jQuery

Here the code I have tried to use to do what I want it to do. 在这里,我尝试使用代码来实现我想要的功能。

    function MoveRight() {  
        $(".scrollableContent").css({ margin-left: "-970px" });
        $(".ui-slider-handle").css({ left: "100%" });
        t = setTimeout(function(){MoveLeft()}, 5000);
    }

    function MoveLeft() {
        $(".scrollableContent").css({ margin-left: "0px" });
        $(".ui-slider-handle").css({ left: "0%" });
        t = setTimeout(function(){MoveRight()}, 5000);
    }

Issue is that the scroll bar disappears when I do this. 问题是当我这样做时滚动条消失了。
The reason that I use Margin-left -970px is that is how large the scroll box is. 我使用Margin-left -970px的原因是滚动框有多大。

Any idea why this is happening and how to make it work / fix it. 任何想法,为什么会发生这种情况以及如何使其工作/修复它。

Many Thanks 非常感谢

It'd be better if you use the 'animate' function, instead of the 'css' function. 如果您使用“动画”功能而不是“ css”功能,那会更好。 It'll smoothly scroll to the left and to the right, allowing people to see all of the content, instead of just the ends (better User-Experience) Here's a JSFiddle, with the issues fixed. 它将平滑地左右滚动,使人们可以看到所有内容,而不仅仅是结尾(更好的用户体验)。这是一个JSFiddle,已修复了问题。

http://jsfiddle.net/TGEQf/206/ http://jsfiddle.net/TGEQf/206/

function MoveRight() {  
    $(".scrollableContent").animate({ 'margin-left': '-500px'}, 4500);
    $(".ui-slider-handle").animate({ left: "100%"}, 4000);
    t = setTimeout(function(){MoveLeft()}, 5000);
}

function MoveLeft() {
    $(".scrollableContent").animate({ 'margin-left': '0px'}, 4500);
    $(".ui-slider-handle").animate({ left: "0%"}, 4000);
    t = setTimeout(function(){ MoveRight() }, 5000);
}

Use Like 使用喜欢

$(".scrollableContent").css({ 'margin-left' : '-970px' });
        $(".ui-slider-handle").css({ left: "100%" });
        t = setTimeout(function(){MoveLeft()}, 5000);

Add 'margin-left' : '-970px' instead of Double Quotes 添加'margin-left' : '-970px'而不是双引号

Demo 演示版

You have to put quotes in the css property in your functions. 您必须在函数的css属性中加上引号。 You missed the quotes on margin-left and left property in your moveRight and moveLeft funcitons. 您错过了moveRight和moveLeft函数中margin-left和left属性的引号。

 function MoveRight() {  
    $(".scrollableContent").css({ 'margin-left': "-970px" });
    $(".ui-slider-handle").css({ 'left': "100%" });
    t = setTimeout(function(){MoveLeft()}, 5000);
}


function MoveLeft() {
    $(".scrollableContent").css({ 'margin-left': "0px" });
    $(".ui-slider-handle").css({ 'left': "0%" });
    t = setTimeout(function(){MoveRight()}, 5000);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM