scrolltop

Jquery: Using scrollTop to make animated sticky menu

帅比萌擦擦* 提交于 2019-12-24 13:19:19
问题 I'm trying to create an animated sticky menu. User loads up the page and the navigation is stationary. User then scrolls down the page and after like 500 pixels (scrolling over the original navigation), the navigation animates into the page stuck to the top using fixed positioning. I have it working now (see codepen: http://codepen.io/chrisyerkes/pen/uoFKl) however, once I scroll back up and it resets the menu's position, the next time I scroll down the page, it no longer animates in, just

DIV position change while scrolling down using scrollTop(); - jQuery

落花浮王杯 提交于 2019-12-24 08:37:10
问题 I'm stuck with this, hope any of you can help me out. I have this HTML: <body> <div id="one"></div> <div id="two"></div> <div id="three"></div> <body> With this CSS: #one, #two, #three { width: 100%; height: auto; } And this jQuery: $(window).scroll(function(){ var y = $(window).scrollTop(); var one = $('#one').height(); var two = $('#two').scrollTop(); var three = $('#three').scrollTop(); var pos_one = 310; var pos_two = 454; var pos_three = 596; if( y > one ){ $("#header").fadeIn(200); }

JavaScript/jQuery add class when element comes into viewport?

五迷三道 提交于 2019-12-24 08:04:10
问题 Is there a way to add a class when the element that I want to apply the class to comes into the viewport? Or when the bottom of the screen is a certain distance past the top of the element? Right now I have the effect that I want using something like this: if ($(document).scrollTop() > 100) { $(".graph-line.two").addClass("graph-75"); The problem with this is that it's relative to the document height, so when I shrink the page (or view on mobile) and the elements stack on top of each other,

js获取网页的各种高度和宽度

风格不统一 提交于 2019-12-23 20:48:09
document.body.clientWidth ==> BODY对象宽度 document.body.clientHeight ==> BODY对象高度 document.documentElement.clientWidth ==> 可见区域宽度 document.documentElement.clientHeight ==> 可见区域高度 网页可见区域宽: document.body.clientWidth 网页可见区域高: document.body.clientHeight 网页可见区域宽: document.body.offsetWidth (包括边线的宽) 网页可见区域高: document.body.offsetHeight (包括边线的高) 网页正文全文宽: document.body.scrollWidth 网页正文全文高: document.body.scrollHeight 网页被卷去的高: document.body.scrollTop 网页被卷去的左: document.body.scrollLeft 网页正文部分上: window.screenTop 网页正文部分左: window.screenLeft 屏幕分辨率的高: window.screen.height 屏幕分辨率的宽: window.screen.width 屏幕可用工作区高度:

Why jQuery has to receive 2 objects: body & html when scrolling whole page with animation?

早过忘川 提交于 2019-12-23 16:53:39
问题 In all the tutorials I found around the web on animating scrolling of the page with jQuery, I found that most of them are using the following code to do that: $("html, body").animate(.... I was trying to find out why it's needed to animate 2 objects: html and body, but not luck. I might think it's needed to cover all major browsers… But why really, can someone explain please? 回答1: chrome/safari uses html to animate, while firefox uses body (might be the other way around, don't remember!) You

Scrolling/Scrollbar Locks After Scrolltop Animation

牧云@^-^@ 提交于 2019-12-23 07:16:49
问题 I've got a few anchors that link to specific sections (using hashtags) within the page, and ones that scroll to the top or bottom of the document window. $("html, body").animate({ scrollTop: $(document).height() }, 2000); However, as soon as the animation and scrolling has reached it's destination and completed, the document scrolling and scrollbar seem to disable for a few seconds. For example, if click a "Go to bottom of page" link, my document window will scroll to the bottom of the page

Even simplest .scrollTop() example returns 0

穿精又带淫゛_ 提交于 2019-12-23 06:10:35
问题 I need to find vertical position of element relative to viewport. I found that jquery .scrollTop() function is for this, but it returns 0. It does return correct value when checking $(document)'s scrollTop instead, but I need element's position, not window position. Am I doing something wrong? HTML: 1<br> <span>2</span> <div style="height:10000px"></div> JavaScript: $(window).scroll(function() { console.log($("span").scrollTop()) }) Jsfiddle: http://jsfiddle.net/kwVC7/ I guess I can make this

Responsive scrolltop

给你一囗甜甜゛ 提交于 2019-12-22 01:19:05
问题 Im using the following code to detect when an object should become 'sticky' and stay fixed in its content. var $window = $(window), $stickyEl = $('#single-post-details'), elTop = $stickyEl.offset().top; $window.scroll(function() { $stickyEl.toggleClass('sticky', $window.scrollTop() + 52 > elTop); }); However I would like to make this responsive. This means that somehow it needs to detect the height of the banner above it first so that it doesn't trigger at the wrong point.. Here is a fiddle

微信小程序商品列表滑动联动商品分类

China☆狼群 提交于 2019-12-21 19:56:30
效果仿x团小程序的商品列表滚动时,联动商品分类的效果。 简单描述思路: 1、商品列表做出不同分类的标记位置 2、监听商品列表滚动时,是否到达分类标记位置的高度 3、符合达到标记位置的高度后,触发商品分类栏目选中事件 注意:我的商品分类栏目和商品列表同属一个页面,但分别是两个不同的components,所以触发事件需要传参 正文部分: 先观察下图:留意红色标注部分,这个高度在获取商品列表数据后,通过下面代码获取 // 获取商品数组的位置信息 const query = this.createSelectorQuery() query.selectAll('.category-name').boundingClientRect() query.exec((res)=> { for(let i=0;i<res[0].length;i++){ // console.log(res[0][i].top) this.data.categoryNameHeight[i].top=res[0][i].top - res[0][0].top } // res[0].top // #the-id节点的上边界坐标 // res[1].scrollTop // 显示区域的竖直滚动位置 }) 第二步监听商品列表滚动时,标记高度的逻辑判断 checkScrool: function(e) { if (this

NSScrollView scrollToTop

拈花ヽ惹草 提交于 2019-12-21 12:13:51
问题 Does anyone know the correct way to scroll the NSScrollView to the top? I was looking for an equivalent to the UIView's scrollToTop method. This is what I have so far, but its not quite right under all situations [self.contentView scrollToPoint:NSMakePoint(0, MAX(contentView.frameHeight, ((NSView*)self.documentView).frameHeight))]; 回答1: Updated for Swift 5 : If your document view is flipped: scrollView.documentView?.scroll(.zero) otherwise: if let documentView = scrollView.documentView {