简体   繁体   English

CSS时间轴滚动条

[英]CSS Timeline scroller

Respected people ... 尊敬的人...

Im working on a timeline scroller which is giving me problems when i scroll left .... 我正在使用时间轴滚动条,当我向左滚动时给我一些问题....

The values are not being subtracted linearly but being added alternatively ... 这些值不是线性相减,而是交替相加...

I have checked the js many times but unable to figure it out ... 我已经多次检查过js,但无法弄清楚...

http://codepen.io/akashdevaraju/pen/tiesa http://codepen.io/akashdevaraju/pen/tiesa

  $("#right,#left").click ->
    id = this.id
    patt = /\d+/g
    circles = $(".circle")    
    if id is "right"
      for cir in circles
        left = $(cir).css("left")
        lef = parseInt(left.match(patt))          
        le = lef - 80            
        $(cir).css("left","#{le}px")
    else
      for cir in circles.toArray().reverse()        
        left = $(cir).css("left")
        lef = parseInt(left.match(patt))          
        le = lef + 80
        $(cir).css("left","#{le}px")

Kindly do help ... 请帮忙...

Try with the code below instead. 请尝试使用下面的代码。 I've modified a bit your regex so it won't strip the '-' sign in front of: eg '-80px' and will return '-80'. 我已经对您的正则表达式进行了一些修改,因此它不会去除前面的'-'符号:例如'-80px'并返回'-80'。 Your regex returned '80' even for negative values. 您的正则表达式即使为负值也返回“ 80”。 When pressing the left button, the negative left offset was messed up by the regex and all those circles shared the same offset... 按下左按钮时,正则表达式弄乱了负的左偏移量,所有这些圆共享相同的偏移量...

$("#right,#left").click ->
    id = this.id 
    patt = /(-)*[0-9]+/g
    circles = $(".circle") 

    for cir in circles
        left = $(cir).css("left")
        lef = parseInt(left.match(patt))
        le = if id is "right" then lef - 80 else lef + 80

        $(cir).css("left","#{le}px")

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

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