作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经使用 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/
我是一名优秀的程序员,十分优秀!