javascript - How to animate horizontal scroll html - Stack Overflow

I saw online that you could use the code at the bottom to animate a horizontal link (fiddle demo at the

I saw online that you could use the code at the bottom to animate a horizontal link (fiddle demo at the bottom). I am somewhat of a beginner to html, and would like to use this in the context of having an a link such as the following:

<a href="#nav">click this link</a>

<a name="nav" class="testing">anchor</a>

animate the webpage scrolling horizontally to the anchor. Here is the code with which I would like to do this:

function goToByScrollHoriz(id){
    $('html,body').animate({
        scrollLeft: $("#"+id).offset().left
    },'slow');
}

/

can anybody walk me through how?
Thank you

I saw online that you could use the code at the bottom to animate a horizontal link (fiddle demo at the bottom). I am somewhat of a beginner to html, and would like to use this in the context of having an a link such as the following:

<a href="#nav">click this link</a>

<a name="nav" class="testing">anchor</a>

animate the webpage scrolling horizontally to the anchor. Here is the code with which I would like to do this:

function goToByScrollHoriz(id){
    $('html,body').animate({
        scrollLeft: $("#"+id).offset().left
    },'slow');
}

http://jsfiddle/qS2Ke/1/

can anybody walk me through how?
Thank you

Share Improve this question asked Mar 6, 2016 at 14:59 BlaineBlaine 3421 gold badge4 silver badges19 bronze badges 3
  • Have you tried anything? – Roko C. Buljan Commented Mar 6, 2016 at 15:01
  • @RokoC.Buljan yes, but I'm so lost i don't even know how to describe it. I've pretty much tried replacing the "id" in the original code with "nav", then tried creating another tag and surrounding both links with divs, but none of that has done anything – Blaine Commented Mar 6, 2016 at 15:04
  • 1 @Blaine This is a simple approach of how you can do this: jsfiddle/qS2Ke/22 – marcelo2605 Commented Mar 6, 2016 at 15:10
Add a ment  | 

1 Answer 1

Reset to default 6

You need anchor elements like

<a href="#d1"> d1 </a>

and target elements like

<div class="placeholder" id="d1">

than using this jquery

function horizAnim(event) {
  event.preventDefault();
  $('html,body').animate({
    scrollLeft: $(this.hash).offset().left
  }, 'slow');
}

$("a").on("click", horizAnim);

this is what you get.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744209202a4563253.html

相关推荐

  • javascript - How to animate horizontal scroll html - Stack Overflow

    I saw online that you could use the code at the bottom to animate a horizontal link (fiddle demo at the

    8天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信