gpt4 book ai didi

JavaScript 未按预期更新网站 Logo 大小

转载 作者:行者123 更新时间:2023-11-28 16:34:08 26 4
gpt4 key购买 nike

我正在向我的网站添加代码,以便我的 Logo 适当调整大小。

我为 Logo 编写了一个 JavaScript 函数,以根据窗口宽度调整大小。不幸的是,当我这样做时, Logo 只是恢复到原来的大小。如果我对图像应用内联样式以设置宽度,它会起作用,但如果图像的大小由 CSS 文件或我的 JavaScript 决定,则 Logo 将保持其原始大小。

这是我的 index.html 文件的头部:

 <!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Computer Repair and Services</title>
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="author" content="Athena Harting" />
<link rel="shortcut icon" href="../favicon.ico">
<link rel="stylesheet" type="text/css" href="css/default.css" />
<link rel="stylesheet" type="text/css" href="css/component.css" />
<script src="js/modernizr.custom.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="js/MobileMenu.js"></script>
<script src="js/WidthMargin.js"></script>
<script src="js/MobileLogo.js"></script>
</head>
<body>
<div class="container">
<header>
<div class="logospace" id="logospace"><img src="imgs/Logo_Glossy_Web.png"/></div>
<h1>Athenian Computers<span>Founded and operated out of Shoreline, WA</span></h1>
</header>

您会注意到我在该文件中引用了一个 MobileLogo.js 和一个 default.css 文件。

这是应该应用于我的 default.css 文件中我的 Logo 的相关代码:

/* TEST STUFF */

.logospace {
width: 200px;
height: 200px;
}

这是我的 MobileLogo.js 文件。此文件应根据页面宽度适当调整我的 Logo 的大小:

var resize = function(){

var wi = $(window).width();

if(wi <= 519){
$("#logospace").css({
'width' : '50px'
'height' : '50px'

});
}
else if (wi <= 799){
$("#logospace").css({
'width' : '100px'
'height' : '100px''

});
}
else if (wi <= 980){
$("#logospace").css({
'width' : '150px'
'height' : '150px'

});
}
else{
$("#logospace").css({
'width' : '200px'
'height' : '200px'

});
}
}

$(window).ready(function() {
resize();

$(window).resize(function() {
resize();
});
});

谁能告诉我哪里出了问题?

最佳答案

您在 'height' : '100px'' 中有一个额外的 '。您可能想要删除它。

关于JavaScript 未按预期更新网站 Logo 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31257048/

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