gpt4 book ai didi

javascript - 如何在 html 中获取 JavaScript 函数

转载 作者:行者123 更新时间:2023-11-30 10:17:29 26 4
gpt4 key购买 nike

我已经使用 Java 一段时间了,现在正在转向 Web 开发 - 但是我遇到了一些麻烦,我的代码:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">

var getHeight = function() {

return $(window).height();

}

</script>

我想在这里获取窗口的高度,

img.pos_fixed {

position:fixed;
top:getHeight() / 2;
right:250px;

}

但它不显示在屏幕中间。我是新手,所以请不要责备我,我应该像现在这样学习 html/javascript/css。

最佳答案

你可以关闭你的 jquery 脚本标签,

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">
</script>

并使用纯CSS

img.pos_fixed {
position:fixed;
top:50%;
right:250px;
}

编辑

替代 JavaScript,您可能应该等待 document.ready -

$(document).ready(function() {
$("img.pos_fixed").css('top','50%'); // same css
});

关于javascript - 如何在 html 中获取 JavaScript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23124127/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com