[英]Simple js add for 3d
Im not sure why its not working, I've tried many different ways but it doesnt want to work, what am i doing wrong? 我不确定为什么它不起作用,我尝试了许多不同的方法,但它不想起作用,我在做什么错?
Im trying to add 3D inset parallax Effect 我正在尝试添加3D嵌入式视差效果
my html 我的HTML
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TITLE</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<link href="3d.js" type="text/javascript" />
</head>
<body>
<div class="inset" style="margin:0 auto">
TEXT HERE
</div>
<h1>3D Inset Parallax Effect</h1>
<p class="inset">The following is an example of how you can create the illusion of a 3D inset block-level element (with parallax on scroll position) using some basic CSS and jQuery. To see the effect in action, just scroll the page.</p>
<h2>Example Form:</h2>
<form>
<label>
First Name:
<input class="inset" type="text" placeholder="Enter First Name" />
</label>
<label>
Last Name:
<input class="inset" type="text" placeholder="Enter Last Name" />
</label>
</body>
</html>
my 3d.js file contains this 我的3d.js文件包含此
var insets = $('.inset'),
origBorderWidth = parseInt(insets.css('border-top-width')),
win = $(window);
function set3D() {
var windowHeight = win.height();
insets.each(function() {
var self = $(this),
scrollHeight = win.scrollTop(),
elementPosition = self.position(),
positionPercentTop = Math.round((elementPosition.top - scrollHeight) / windowHeight * 100),
positionPercentBottom = Math.round((elementPosition.top + self.outerHeight() - scrollHeight) / windowHeight * 100);
self.css({
'border-top-width' : origBorderWidth - (origBorderWidth * (positionPercentTop / 100)) + 'px',
'border-bottom-width' : origBorderWidth * (positionPercentBottom / 100) + 'px'
});
});
};
win.on('load scroll resize', function() {
set3D();
});
The issue im having is obviosly conecting the js code with the page, ive tried putting it between in the head, body. 我遇到的问题是将js代码与页面强行联系起来,我尝试将其放在头部,正文之间。 It just doest work.
它只是行不通。
The CSS works percetly and it all appears fine its just the JS CSS可以正常工作,而只是JS看起来一切正常
You're not referencing the script properly. 您没有正确引用脚本。 The JavaScript file that you're trying to include needs to be in an opening and closing
<script></script>
tag. 您要包含的JavaScript文件必须位于开始和结束
<script></script>
标记中。 Here's the reference to the documentation 这是对文档的参考
http://www.w3.org/TR/html4/interact/scripts.html#h-18.2.1 http://www.w3.org/TR/html4/interact/scripts.html#h-18.2.1
You should put your JavaScript file like so, making sure it's within the opening and closing <head></head>
tags. 您应该这样放置JavaScript文件,确保它位于开始和结束
<head></head>
标记内。 Which from your code I can see it already is. 从您的代码中我已经可以看到。
<script type="text/javascript" src="3d.js"></script>
I spotted at least 3 errors in your html: 我在您的html中发现至少3个错误:
<link>
can't be used to insert Javascript in a page. <link>
不能用于在页面中插入Javascript 。 You should use <script>
: <script>
: <script type="text/javascript" src="3d.js"></script>
<body>
, at its end. <body>
的末尾。 $(document).ready(function() { /* your code */ });
$(document).ready(function() { /* your code */ });
Hope it helps. 希望能帮助到你。 Bye!
再见!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.