【问题标题】:Can't get these scripts to work together无法让这些脚本一起工作
【发布时间】:2015-09-08 09:32:08
【问题描述】:

我是一名在 IT 公司实习的二年级应用程序开发学生,我的主管要求我制作一个下拉菜单,该下拉菜单的外观和功能与顶部 http://www.veermanict.nl/ 在移动模式下的菜单完全相同(您必须将窗口大小调整为移动分辨率才能看到我在说什么)。

我是一个新手,我已经为此苦苦挣扎了两天。 JavaScript 甚至还没有涵盖在我的教育中,所以我基本上在这里学习一切,谷歌搜索知识。我找到了一个可以在 CSS 中修改的模板,让它看起来更像我的主管想要的,但问题是我似乎无法让它工作。

我说的是这个脚本:http://codepen.io/pedronauck/pen/fcaDw

我尝试制作一个 HTML 文档并将 CSS 和 JavaScript 链接到 HTML 页面,如下所示:

<head>
<meta charset="utf-8">
<title>Menu Test 2</title>
<link rel="stylesheet" type="text/css" href="style2.css">
<script language="javascript" type="text/javascript" src="jquery-1.11.3.min.js"></script>
<script language="javascript" type="text/javascript" src="dropdown.js"></script>
</head>

...但它只会显示为:prntscr (dot) com/8dxk4s(我不允许多个链接,抱歉)

这意味着 CSS 确实有效。但是Javascript没有?据我所知,Dreamweaver 中的 CSS 内部也存在错误。 JavaScript 不是在规则 25 处缺少分号吗?

请帮帮我。我不想让我的主管认为我没用。但我坚持这一点,他太忙了,无法帮助我。我尝试了十几种其他选择,但他并不满足于平庸。

【问题讨论】:

  • 除非我错过了,否则您似乎没有发布您遇到问题的脚本(dropdown.js?)。
  • 你应该在body标签的末尾加载jquery
  • 我认为这并不重要。据我所知,脚本的位置应该在一个地方。我认为这不可能是流量错误。这些都没有真正帮助我。
  • @SamHH 查看 codepen 链接。下拉 Javascript 在右侧的框中。
  • 您的js 文件是在同一页面中还是在另一个文件夹中。如果您在另一个文件夹中,则必须提供该路径

标签: javascript html css compilation


【解决方案1】:

SCSS 转换为CSS 使用这个 css

CSS

@import url("http://fonts.googleapis.com/css?family=Lato:300,400,700,900");
@import url(http://fonts.googleapis.com/css?family=Pacifico);
body {
  font-family: "Lato", Helvetica, Arial;
  font-size: 16px;
}

.text-center {
  text-align: center;
}

*, *:before, *:after {
  -webkit-border-sizing: border-box;
  -moz-border-sizing: border-box;
  border-sizing: border-box;
}

.container {
  width: 350px;
  margin: 50px auto;
}

.container > ul {
  list-style: none;
  padding: 0;
  margin: 0 0 20px 0;
}

.title {
  font-family: 'Pacifico';
  font-weight: norma;
  font-size: 40px;
  text-align: center;
  line-height: 1.4;
  color: #2980B9;
}

.dropdown a {
  text-decoration: none;
}

.dropdown [data-toggle="dropdown"] {
  position: relative;
  display: block;
  color: white;
  background: #2980B9;
  box-shadow: 0 1px 0 #409ad5 inset, 0 -1px 0 #20638f inset;
  text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.3);
  padding: 10px;
}

.dropdown [data-toggle="dropdown"]:hover {
  background: #2c89c6;
}

.dropdown .icon-arrow {
  position: absolute;
  display: block;
  font-size: 0.7em;
  color: #fff;
  top: 14px;
  right: 10px;
}

.dropdown .icon-arrow.open {
  transform: rotate(-180deg);
  transition: transform 0.6s;
}

.dropdown .icon-arrow.close {
  transform: rotate(0deg);
  transition: transform 0.6s;
}

.dropdown .icon-arrow:before {
  content: '\25BC';
}

.dropdown .dropdown-menu {
  max-height: 0;
  overflow: hidden;
  list-style: none;
  padding: 0;
  margin: 0;
}

.dropdown .dropdown-menu li {
  padding: 0;
}

.dropdown .dropdown-menu li a {
  display: block;
  color: #6e6e6e;
  background: #EEE;
  box-shadow: 0 1px 0 white inset, 0 -1px 0 #d4d4d4 inset;
  text-shadow: 0 -1px 0 rgba(255, 255, 255, 0.3);
  padding: 10px 10px;
}

.dropdown .dropdown-menu li a:hover {
  background: #f6f6f6;
}

.dropdown .show, .dropdown .hide {
  transform-origin: 50%, 0%;
}

.dropdown .show {
  display: block;
  max-height: 9999px;
  transform: scaleY(1);
  animation: showAnimation 0.5s ease-in-out;
  -moz-animation: showAnimation 0.5s ease-in-out;
  -webkit-animation: showAnimation 0.5s ease-in-out;
  transition: max-height 1s ease-in-out;
}

.dropdown .hide {
  max-height: 0;
  transform: scaleY(0);
  animation: hideAnimation 0.4s ease-out;
  -moz-animation: hideAnimation 0.4s ease-out;
  -webkit-animation: hideAnimation 0.4s ease-out;
  transition: max-height 0.6s ease-out;
}

@keyframes showAnimation {
  0% {
    transform: scaleY(0.1);
  }
  40% {
    transform: scaleY(1.04);
  }
  60% {
    transform: scaleY(0.98);
  }
  80% {
    transform: scaleY(1.04);
  }
  100% {
    transform: scaleY(0.98);
  }
  80% {
    transform: scaleY(1.02);
  }
  100% {
    transform: scaleY(1);
  }
}

@-moz-keyframes showAnimation {
  0% {
    transform: scaleY(0.1);
  }
  40% {
    transform: scaleY(1.04);
  }
  60% {
    transform: scaleY(0.98);
  }
  80% {
    transform: scaleY(1.04);
  }
  100% {
    transform: scaleY(0.98);
  }
  80% {
    transform: scaleY(1.02);
  }
  100% {
    transform: scaleY(1);
  }
}

@-webkit-keyframes showAnimation {
  0% {
    transform: scaleY(0.1);
  }
  40% {
    transform: scaleY(1.04);
  }
  60% {
    transform: scaleY(0.98);
  }
  80% {
    transform: scaleY(1.04);
  }
  100% {
    transform: scaleY(0.98);
  }
  80% {
    transform: scaleY(1.02);
  }
  100% {
    transform: scaleY(1);
  }
}

@keyframes hideAnimation {
  0% {
    transform: scaleY(1);
  }
  60% {
    transform: scaleY(0.98);
  }
  80% {
    transform: scaleY(1.02);
  }
  100% {
    transform: scaleY(0);
  }
}

@-moz-keyframes hideAnimation {
  0% {
    transform: scaleY(1);
  }
  60% {
    transform: scaleY(0.98);
  }
  80% {
    transform: scaleY(1.02);
  }
  100% {
    transform: scaleY(0);
  }
}

@-webkit-keyframes hideAnimation {
  0% {
    transform: scaleY(1);
  }
  60% {
    transform: scaleY(0.98);
  }
  80% {
    transform: scaleY(1.02);
  }
  100% {
    transform: scaleY(0);
  }
}

【讨论】:

  • 谢谢,我试过了,但我仍然得到和以前一样的结果。看起来还是和 prntscr.com/8dxk4s 一样
【解决方案2】:

您正在使用 SCSS (Sass) 代码,就好像它是原始 CSS。在您提供的 Codepen 中,它通过将 CSS 更改为 SCSS 立即开始工作。

【讨论】:

  • 很抱歉,我是新手,但我从未听说过 SCSS。是否可以将其转换为常规 CSS3?还是我必须学习 SCSS?
  • @Amitsingh 我试过这个,但它给了我这个错误:'找不到导入的文件或不可读:compass/css3 当前目录:第 2 行第 9 列'
  • 这意味着您必须导入compasscss 文件,请参阅谎言2 @import compass/css3;,您应该下载该文件以使用指南针样式
  • 哦....我真的不明白你的意思...我应该把@import compass/css放到第2行吗?抱歉,我以前从来没有使用过这种代码,我觉得很愚蠢,现在这一切都在大量涌现。我的大脑需要处理这个......
  • @Reallyloudgirl 检查我的答案转换为cssscss 文件
【解决方案3】:

脚本标签的语言属性已弃用。使用类型,而不是两者。或者根本不使用它。在所有现代网络浏览器上,类型的默认值是 text/javascript。

【讨论】:

  • 但这并不能解决我的问题。我猜这对于使用旧的/晦涩的浏览器的人来说只是一些冗余/预防措施,但这不是破坏我的代码的原因。
  • 嗯,你试过了吗?
  • 我做了,没有骰子,对不起。
  • 这是您用于下拉菜单的脚本吗? github.com/twbs/bootstrap/blob/master/js/dropdown.js
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-27
  • 1970-01-01
  • 1970-01-01
  • 2020-02-29
  • 2011-04-25
  • 2014-11-22
相关资源
最近更新 更多