scrolltop

jQuery add and remove $(window).scroll(function()?

旧巷老猫 提交于 2019-12-03 04:20:38
How can I remove and then add the $(window).scroll ? I need to store a variable and reuse it after some event. // here i store my var $(window).scroll(function(){ myScroll = $(window).scrollTop() }); $("#itemUnbind").click(function(){ // here i need to remove the listener }); $("#itemBind").click(function(){ // here i need to add listener again }); Thank you. You need to store the function in a variable and then use off to remove it: var scrollHandler = function(){ myScroll = $(window).scrollTop(); } $("#itemBind").click(function(){ $(window).scroll(scrollHandler); }).click(); // .click() will

Javascript scroll to div id [closed]

匿名 (未验证) 提交于 2019-12-03 03:05:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've searched on google the solution to my problem, and I can't understand why the code I've written work to all, but to me don't. I've written this: <head> <meta charset="utf-8" /> <title></title> <script type="text/javascript"> function scrollTo() { $('html, body').animate({ scrollTop: $('#div_id').offset().top }, 'slow'); return false; } </script> <style type="text/css"> .uno { height: 1000px; background: #808080; } .due { margin-top: 300px; height: 500px; background: #ff00ff; } </style> </head> <body> <div class="uno" onclick="scrollTo()

Disabling iOS elastic body scroll &amp; keep native scrolling working [duplicate]

匿名 (未验证) 提交于 2019-12-03 02:18:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: iPhone Web App - Stop body scrolling 6 answers I am currently working on a single page web app optimized for touch devices, mainly iOS. I've implemented the new iOS native scrolling via -webkit-overflow-scrolling: touch; and all works well except that we are still experiencing the apple elastic scroll effect on the whole page body. This involves the whole page moving off the top/bottom of the viewport when a scroll ends or the body is pushed and really gives away the fact that this is a web app. I

jQuery .scrollTop(); + animation

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I set the page to scroll to top when a button is clicked. But first I used an if statement to see if the top of the page was not set to 0. Then if it's not 0 I animate the page to scroll to the top. var body = $("body"); var top = body.scrollTop() // Get position of the body if(top!=0) { body.animate({scrollTop:0}, '500'); } The tricky part now is animating something AFTER the page has scrolled to the top. So my next thought is, find out what the page position is. So I used console log to find out. console.log(top); // the result was 365

Accounting for a fixed header with animate.scrolltop and (target).offset().top;

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This should be a pretty basic question, but i've thrown most of my morning at it, and at this point I'm close to throwing in the towel. I have not even a little bit of js foo -- but I found a nicely commented chunk of code that I'm hoping to use to animate anchor links it is: $(document).ready(function() { $('a[href*=#]').bind('click', function(e) { e.preventDefault(); //prevent the "normal" behaviour which would be a "hard" jump var target = $(this).attr("href"); //Get the target var scrollToPosition = $(target).offset().top; // perform

Run ScrollTop with offset of element by ID

匿名 (未验证) 提交于 2019-12-03 01:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Trying to make the browser scroll to a specific ID with an added offset - $('html, body').animate({scrollTop: $('#contact').offset().top}, 'slow'); What I need to do is to set the offset by -100px. How can I accomplish this? 回答1: No magic involved, just subtract from the offset top of the element $('html, body').animate({scrollTop: $('#contact').offset().top -100 }, 'slow'); 文章来源: Run ScrollTop with offset of element by ID

Material Design Lite and jQuery, smooth scroll not working

匿名 (未验证) 提交于 2019-12-03 01:23:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am unable to use .animate method of jQuery with Google's Material Design Lite(MDL). I have used MDL to make navigation bar, but smooth scrolling was not working. Simple jQuery code is this: $(function(){ $('a.smooth').click(function(){ console.log("SMOOTH BEGIN"); var speed = 1000; var href= $(this).attr("href"); var target = $(href == "#" || href == "" ? 'html' : href); var position = target.offset().top; $("html, body").animate({scrollTop:position}, speed, "swing"); console.log("SMOOTH END"); }); }); And simple html code is this: Home

How to get scrollTop of an iframe

匿名 (未验证) 提交于 2019-12-03 01:10:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: jQuery's scrollTop returns null when window is an iframe. Has anyone been able to figure out how to get scrollTop of an iframe? more info: my script is running in the iframe itself, the parent window is on another domain, so I can't access the ID of the iframe or anything like that 回答1: You can set scrollTop by using this setup: $("html,body").scrollTop(25); So you could try getting it like this: $("html,body").scrollTop(); Because different browsers set the scrollTop on different elements (body or html). From the scrollTo plugin: But that

JS实现歌词同步滚动效果

匿名 (未验证) 提交于 2019-12-03 00:38:01
实现歌词同步滚动效果,首先要用 audio 标签引入音频 < div id = "h_center1" > < span > 当前播放: </ span > < span > 大鱼海棠 </ span > < audio id = "now_music" src = "双笙 - 大鱼.mp3" > </ audio > < img src = "picture/former.jpg" /> < img src = "picture/stop.jpg" class = "clickToStop" width = "21" height = "58" /> < img src = "picture/next.jpg" /> </ div > 并且也要将歌词文件写入 textarea 文本域内并隐藏,然后在获取歌词时放入指定位置 <textarea id = "lrc_content" name = "textfield" cols= "70" rows= "10" style= "display:none;" > [ti:大鱼] [ar:王若伊] [al:大鱼] [ly:尹约] [mu:钱雷] [ma:] [pu:] [ by :ttpod] [total: 278752 ] [ offset : 0 ] [ 00 : 00.410 ]大鱼 - 王若伊 [ 00 : 01.410