我不知道爲什麼它不工作,我嘗試了很多不同的方式,但它不想工作,我做錯了什麼?簡單的js添加爲3d
我試着添加3D視差的插圖影響
我的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>
我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();
});
有被obviosly conecting與JS代碼的問題IM我試圖把它放在頭部,身體之間。它只是工作。
的CSS工作percetly,這一切顯示正常它就是JS