我正在尝试这个 javascript 滑动滚动效果,当一个对象在它上面滚动时图像会改变颜色并且我拥有与教程完全相同的所有代码,除了 javascript 不会触发? This is the tutorial I used. 这是我得到的 html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Slip Scroll</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container dark">
<img src="images/logogreen.svg" class="default" height="200px">
</div>
<div class="container light">
<img src="images/logopink.svg" class="moveable" height="200px">
</div>
<div class="container dark">
<img src="images/logogreen.svg" class="moveable" height="200px">
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="js/slipScroll.js"></script>
</body>
</html>
这是我使用的 javascript:
var setLogo = function() {
$('.moveable').each(function() {
$(this).css('top',
$('.default').offset().top -
$(this).closest('.container').offset().top
);
});
};
$(document).scroll(function() {
setLogo();
});
setLogo();
最佳答案
$('.default').offset().top - $(this).closest('.container').offset().top + 'px'
在这条线上你正试图
Int- int + string
这可能会导致问题,因此需要:
($('.default').offset().top - $(this).closest('.container').offset().top).toString + 'px'
关于Javascript 不会火?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26307130/