将Jquery转换为Javascript [英] Converting Jquery to Javascript
本文介绍了将Jquery转换为Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对不起,我在JQuery方面很差.
Sorry, I am am very poor at JQuery.
对于我的需求,我得到了一个代码,即Jquery.任何人都可以将其转换为普通的javascript
I got one code for my requirement which is Jquery. Can any one please convert it into plain javascript
$(window).scroll(function() {
var scrollTop = $(window).scrollTop();
$("#mybox").css("top", scrollTop + "px");
});
css部分
#mybox
{
position:absolute;
width:200px;
height:50px;
background-color:red;
}
我正在使用它,即使用户在页面中导航,它也会在页面底部显示一个浮动链接
I am using it display a floating link at the bottom of the page even if user navigated through the page
<script type="text/javascript">
window.addEventListener('scroll', function() {
var scrollTop = window.pageYOffset;
document.getElementById('worklist').style.top = scrollTop;
});
</script>
<div id="worklist" style="position: absolute; bottom: 5px; right: 50px;">
<a href="LinkHere"><h2>Work List</h2></a>
</div>
推荐答案
我猜想这可能就是您想要的:
I'm guessing that maybe this is what you want:
window.addEventListener('scroll', function() {
var scrollTop = window.pageYOffset;
document.getElementById('worklist').style.bottom = -scrollTop + "px";
});
这会将您的链接保留在页面的底部.
This will keep your link at the bottom of the page.
希望这会有所帮助!
安迪.
这篇关于将Jquery转换为Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文