scrolltop

JQuery scrollTop function goes to correct position but then jumps back to top of page

随声附和 提交于 2021-02-18 12:27:32
问题 I used the JQuery function scrollTop on a list of contact numbers in a click function for each letter. It scrolls to where it is supposed to but then scrolls back to the top immediately. Here is a sample of the function in the code: $('.a').click(function(){ $('html, body').animate({scrollTop:$('#A').position().top}, 'slow'); }); Here is the JSFiddle I made for it: http://jsfiddle.net/CR47/MdtSE/ 回答1: If you're adding this to an anchor tag, you normally need to add a preventDefault() or

JQuery scrollTop function goes to correct position but then jumps back to top of page

半世苍凉 提交于 2021-02-18 12:27:09
问题 I used the JQuery function scrollTop on a list of contact numbers in a click function for each letter. It scrolls to where it is supposed to but then scrolls back to the top immediately. Here is a sample of the function in the code: $('.a').click(function(){ $('html, body').animate({scrollTop:$('#A').position().top}, 'slow'); }); Here is the JSFiddle I made for it: http://jsfiddle.net/CR47/MdtSE/ 回答1: If you're adding this to an anchor tag, you normally need to add a preventDefault() or

window.scrollTo not scrolling to provided id

我的梦境 提交于 2021-02-10 06:14:31
问题 I am working on a single document file. I want to scroll to the desired section with id="projectpage" when an anchor with id="about" is clicked. <a class="nav-link page-scroll" href="" id="about">About Me</a> <section id="aboutpage"> I tried using $('a#about').click(function(){ $(window).scrollTo(0, document.getElementById('projectpage').offsetTop); }); or even $('#about').click(function(){ $(window).scrollTo(0, document.getElementById('projectpage').offsetTop); }); but nothing works. When I

How can I add text in my scroll to top button which already has an icon in it

99封情书 提交于 2021-01-29 18:18:54
问题 I'm totally new to this field so please help me out. I've tried almost everything but nothing seems to be working. Actually, I want to add some text in my scroll to top button, which has already been made and working perfectly and it has an icon in it. But I want to add some text with that icon. Here's a link what I want to do! Following is the code I have in js file: // Append Button $("body").append($("<a />") .addClass("scroll-to-top") .attr({ "href": "#", "id": "scrollToTop" }) .append( $

jQuery scrollTop in container on click only works once

天大地大妈咪最大 提交于 2020-12-13 12:16:03
问题 I'm trying to make a content slider of sorts with the simplest jQuery possible, without a plugin and without assigning ids to each div. I have a fixed position #container that is 100% width and 45% height of the page and contains 5 divs called .sect . all 5 .sect are 100% width of the container and are also 45% height of the page, which means that 1 .sect would fill the visible portion of #container , when scrolled to. a div #down outside #container should, on click, make the #container

jQuery scrollTop in container on click only works once

扶醉桌前 提交于 2020-12-13 12:14:44
问题 I'm trying to make a content slider of sorts with the simplest jQuery possible, without a plugin and without assigning ids to each div. I have a fixed position #container that is 100% width and 45% height of the page and contains 5 divs called .sect . all 5 .sect are 100% width of the container and are also 45% height of the page, which means that 1 .sect would fill the visible portion of #container , when scrolled to. a div #down outside #container should, on click, make the #container

jQuery scrollTop in container on click only works once

一曲冷凌霜 提交于 2020-12-13 12:11:38
问题 I'm trying to make a content slider of sorts with the simplest jQuery possible, without a plugin and without assigning ids to each div. I have a fixed position #container that is 100% width and 45% height of the page and contains 5 divs called .sect . all 5 .sect are 100% width of the container and are also 45% height of the page, which means that 1 .sect would fill the visible portion of #container , when scrolled to. a div #down outside #container should, on click, make the #container

Add class to body for each scrolling based on section ID

旧巷老猫 提交于 2020-07-20 04:42:23
问题 I have a page layout like this. <body> <section id="s1">...</div> <section id="s2">...</div> <section id="s3">...</div> </body> I need to add class to body tag whenever the <section> meet the top by scrolling. like <body class="s1"> for #s1 section and <body class="s2"> for #s2 . How this can be done using jquery? Please help. 回答1: This is probably what you want: http://jsbin.com/tabolida/1/edit?html,js,output var bodyEl = $("body"); $(window).on("scroll", function() { var scrollTop = $(this)

Add class to body for each scrolling based on section ID

蹲街弑〆低调 提交于 2020-07-20 04:42:06
问题 I have a page layout like this. <body> <section id="s1">...</div> <section id="s2">...</div> <section id="s3">...</div> </body> I need to add class to body tag whenever the <section> meet the top by scrolling. like <body class="s1"> for #s1 section and <body class="s2"> for #s2 . How this can be done using jquery? Please help. 回答1: This is probably what you want: http://jsbin.com/tabolida/1/edit?html,js,output var bodyEl = $("body"); $(window).on("scroll", function() { var scrollTop = $(this)