用户滚动页面时为文本添加下划线 - JQUERY

我一直在寻找一种在用户向下滚动页面时为文本添加下划线的方法。我希望仅当用户向下滚动时才显示下划线。我尝试过使用 animate.css 和其他插件但无济于事。有任何想法吗?谢谢你!



jeck猫
浏览 50回答 2
2回答

慕尼黑的夜晚无繁华

尝试这个<!DOCTYPE html><html><head><style>p{margin-top : 150px;}</style><script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script><script>$(document).ready(function(){&nbsp; $(window).on('scroll',function(){&nbsp; var a = $(window).scrollTop();&nbsp; //alert(a);&nbsp; if( a > 50) {&nbsp; &nbsp; $("p").css("textDecoration", "underline");&nbsp; &nbsp; }&nbsp; &nbsp; else {&nbsp; &nbsp; &nbsp; &nbsp;$("p").css("textDecoration", "none");&nbsp; &nbsp; }&nbsp; });});</script></head><body><div><p>If you scroll, I will underline myself.</p><p>If you scroll, I will underline myself.</p><p>If you scroll, I will underline myself.</p><p>If you scroll, I will underline myself.</p></div></body></html>您也可以在这里尝试示例。

守着一只汪

这可能会解决您的问题:$(document).on("scroll", function(){&nbsp; &nbsp; var topPX = $(window).scrollTop(); //how many pixels the user scrolled&nbsp; &nbsp; if(topPX > 100){&nbsp; &nbsp; //underlines the text once the user scrolls past 100px&nbsp; &nbsp; &nbsp; &nbsp; $('.text').css('text-decoration','underline');&nbsp; &nbsp; }&nbsp; &nbsp; if(topPX < 100){&nbsp; &nbsp; //reverts it back to normal if the user came back to to the "below 100px" position&nbsp; &nbsp; &nbsp; &nbsp; $('.text').css('text-decoration','none');&nbsp; &nbsp; }});
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5