我有一个简单的jQuery脚本,即使内容不够长,也会将页脚推到页面底部:
$(document).ready(function(){
positionFooter();
function positionFooter(){
//get the div's padding
var padding_top = $("#footer").css("padding-top").replace("px", "");
//get the current page height - the padding of the footer
var page_height = $(document.body).height() - padding_top;
var window_height = $(window).height();
//calculate the difference between page and window height
var difference = window_height - page_height;
if (difference < 0)
difference = 0;
//write the changes to the div
$("#footer").css({
padding: difference + "px 0 0 0"
})
}
//re-run the function if browser window is resized …Run Code Online (Sandbox Code Playgroud) 我仔细阅读了"在执行某些事情之前要求jQuery等待所有图像加载的正式方法"的问题,但是IE给了我很多时间.
我想在背景图像加载后淡入一些图像,所以多亏了解释,一切都在FF,Safari和Chrome上运行良好.它似乎不适用于IE浏览器.使用IE 8(8.0.7)在两台不同的计算机上试用它.
有人可以告诉我这个吗?我的网站是http://www.laforcemajeure.nl
这是我的代码,它位于script.js文件的底部:
$(window).load(
function() {
$("#allbirds").fadeIn(2000);
}
);
Run Code Online (Sandbox Code Playgroud) 加载图像后,我无法匹配div的高度.它获得了最高div的高度,但它似乎在图像加载之前得到它.有没有办法解决?这是我到目前为止:
function matchColHeights(col1, col2) {
var col1Height = $(col1).height();
alert('col1 '+col1Height);
var col2Height = $(col2).height();
alert('col2 '+col2Height);
if (col1Height < col2Height) {
$(col1).height(col2Height);
} else {
$(col2).height(col1Height);
}
}
$(document).ready(function() {
matchColHeights('#leftPanel', '#rightPanel');
});
Run Code Online (Sandbox Code Playgroud)
这是一个链接到它的运行位置:http://www.tigerstudiodesign.com/blog/
所以我有一个小的jQuery脚本,根据背景图像的宽高比调整元素大小.在某些情况下,它不能及时工作,我相信这是因为代码在图像完成下载之前运行.
基本上,我有一些<div>元素将具有一定大小的背景图像,我希望元素的大小完全相同.如果有一个比JS更好的方式,我会全力以赴.
我可以手动设置延迟,但有没有办法只在图像完成下载后运行代码?
我目前$(document).ready(function(){...});在我的页脚里面有它.
我正在尝试将所有图像元素放在html页面上然后检查每个图像(如果width < height(纵向)然后旋转它).
问题是我的脚本不适用于每个图像,但对于所有图像,因为我通过"img"标签获取图像,然后我不知道如何应用单个图像的旋转.
是否可以在不必修改每个图像的标记的情况下执行此操作(我想避免为每个图像放置ID)?
<script>
$(document).ready(function() {
var imgs = document.getElementsByTagName("img");
for (var i = 0; i < imgs.length; i++) {
img = document.getElementsByTagName("img")[i];
var width = img.clientWidth;
var height = img.clientHeight;
if(width<height){
img.setAttribute('style','transform:rotate(90deg)'); //how do I apply this for each image?
}
else{
}
}
});
</script>
Run Code Online (Sandbox Code Playgroud) 我怎么知道是否所有使用jQuery加载div
我想在#slider div中加载所有img后执行此操作
var imgHeight = $("#slider img").height();
alert(imgHeight);
Run Code Online (Sandbox Code Playgroud)